package com.ruoyi.system.api.service.impl;

import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jpush.api.push.PushResult;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.ruoyi.common.config.Global;
import com.ruoyi.common.config.JPushConfig;
import com.ruoyi.common.config.PushConfig;
import com.ruoyi.common.jpush.JPushClientUtil;
import com.ruoyi.common.redis.RedisClientUtil;
import com.ruoyi.common.utils.OkHttpUtils;
import com.ruoyi.common.utils.OkHttpUtils2;
import com.ruoyi.system.api.ResponseWithData;
import com.ruoyi.system.api.domain.*;
import com.ruoyi.system.api.mapper.*;
import com.ruoyi.system.api.service.CcService;
import com.ruoyi.system.api.service.IInterfaceOperationLogService;
import com.ruoyi.system.api.service.LocationService;
import com.ruoyi.system.api.service.PokeRequestServe;
import okhttp3.FormBody;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import redis.clients.jedis.Jedis;
import sun.reflect.generics.tree.VoidDescriptor;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * @ClassName CcServiceImpl
 * @Description: TODO
 * @Author shihx
 * @Date 2020/2/24
 * @Version V1.0
 **/
@Service
public class CcServiceImpl implements CcService {

    private static final Logger log = LoggerFactory.getLogger(CcServiceImpl.class);

    /**
     * 配置文件
     */
    @Autowired
    private Global global;

    /**
     * 用户表
     */
    @Autowired
    private UserMapper userMapper;

    /**
     * 接口调用日志
     */
    @Autowired
    private IInterfaceOperationLogService iInterfaceOperationLogService;

    @Autowired
    private ServiceNoticeMapper serviceNoticeMapper;

    @Autowired
    private ServiceInstrumentMapper serviceInstrumentMapper;

    @Autowired
    private InstrumentInfoMapper instrumentInfoMapper;

    @Autowired
    private LocationService locationService;

    @Autowired
    private ServicePartMapper servicePartMapper;

    @Autowired
    private ServiceDetailsMapper serviceDetailsMapper;

    @Autowired
    private PlanDetailsMapper planDetailsMapper;

    @Autowired
    private JPushConfig jPushConfig;

    @Autowired
    private JpushLogMapper jpushLogMapper;

    @Autowired
    private PokeRequestServe pokeRequestServe;


    @Override
    public ResponseWithData<?> getEngineerByTL(String ServiceNoticeId, String TeamleaderId,
                                               String InterfaceType) throws Exception {
        /** 调用CC端接口同步更新TL名下FSE信息 */
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("getEngineerByTL.asmx/getEngineerByTLHandle");
//        url.append("&Teamleader_id=").append(TeamleaderId);

        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("Teamleader_id", TeamleaderId);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.6获取TL名下工程师接口");
        interfaceOperationLog.setInterfaceType(InterfaceType);
        interfaceOperationLog.setServiceNo(ServiceNoticeId);
        interfaceOperationLog.setFseId(TeamleaderId);
        interfaceOperationLog.setInterfaceUrl(url.toString());
//        interfaceOperationLog.setInterfaceRequest(login.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            log.info("调用CC端返回结果：" + interfaceResponseBody);
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        /** 如果调用接口异常直接返回 */
        if ("0".equals(interfaceState)) {
            return new ResponseWithData().success().msg("查询失败 调用CC端获取TL名下工程师接口发生异常").code(202);
        }

        if (res.code() == 200) {
            JSONObject obj = JSON.parseObject(interfaceResponseBody);
            if ("1".equals(obj.getString("status"))) {

                /** 获取CC端TL名下工程师接口信息 */
                JSONArray jsonArr = obj.getJSONArray("record");

                User user1 = new User();
                user1.setEnginnerId(Long.parseLong(TeamleaderId));
                List<User> ulist = userMapper.selectUserList(user1);
                String tname = "";
                if (ulist != null && ulist.size() > 0) {
                    tname = ulist.get(0).getName();
                }

                /** 循环遍历返回的结果，数据库中存在的更新，不存在的插入 */
                if (jsonArr != null && jsonArr.size() > 0) {
                    for (int i = 0; i < jsonArr.size(); i++) {
                        // 获取每个人员信息对象
                        JSONObject jsonObject = jsonArr.getJSONObject(i);
                        // 员工ID
                        String enginner_id = jsonObject.getString("enginner_id") == null ? ""
                                : jsonObject.getString("enginner_id");
                        // 员工姓名
                        String NAME = jsonObject.getString("NAME") == null ? "" : jsonObject.getString("NAME");
                        // 工程师SAP Code
                        String sapcode =
                                jsonObject.getString("sapcode") == null ? "" : jsonObject.getString("sapcode");
                        // WorkDay休假状态  0 上班 1休假-上午 2休假-下午
                        String WorkDay =
                                jsonObject.getString("WorkDay") == null ? "" : jsonObject.getString("WorkDay");
                        User user = new User();
                        user.setEnginnerId(Long.parseLong(enginner_id));
                        List<User> list = userMapper.selectUserList(user);
                        user.setName(NAME);
                        user.setSapcode(sapcode);
//                        if(!TeamleaderId.equals(enginner_id)){
                        user.setWorkday(WorkDay);
//                        }
                        user.setTeamleaderId(TeamleaderId);
                        user.setTeamleaderName(tname);
                        if (list != null && list.size() > 0) {
                            user.setId(list.get(0).getId());
                            user.setUpdateTime(new Date());
                            userMapper.updateUser(user);
                        } else {
                            user.setCreateTime(new Date());
                            userMapper.insertUser(user);
                        }
                    }
                }

            }
        }
        return new ResponseWithData<>().success().msg("更新成功").code(200);
    }

    /**
     * 重写（getEngineerByTL）调用CC端2.6获取TL名下工程师接口更新用户实时数据 重点是：不更新工作状态！！
     *
     * @author: wlf
     * @date: 2020-05-011 14:48
     */
    @Override
    public ResponseWithData<?> getEngineerUnupdateWorkday(String ServiceNoticeId, String TeamleaderId,
                                                          String InterfaceType) throws Exception {
        /** 调用CC端接口同步更新TL名下FSE信息 */
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("getEngineerByTL.asmx/getEngineerByTLHandle");
//        url.append("&Teamleader_id=").append(TeamleaderId);

        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("Teamleader_id", TeamleaderId);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.6获取TL名下工程师接口");
        interfaceOperationLog.setInterfaceType(InterfaceType);
        interfaceOperationLog.setServiceNo(ServiceNoticeId);
        interfaceOperationLog.setFseId(TeamleaderId);
        interfaceOperationLog.setInterfaceUrl(url.toString());
//        interfaceOperationLog.setInterfaceRequest(login.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            log.info("调用CC端返回结果：" + interfaceResponseBody);
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        /** 如果调用接口异常直接返回 */
        if ("0".equals(interfaceState)) {
            return new ResponseWithData().success().msg("查询失败 调用CC端获取TL名下工程师接口发生异常").code(202);
        }

        if (res.code() == 200) {
            JSONObject obj = JSON.parseObject(interfaceResponseBody);
            if ("1".equals(obj.getString("status"))) {

                /** 获取CC端TL名下工程师接口信息 */
                JSONArray jsonArr = obj.getJSONArray("record");

                User user1 = new User();
                user1.setEnginnerId(Long.parseLong(TeamleaderId));
                List<User> ulist = userMapper.selectUserList(user1);
                String tname = "";
                if (ulist != null && ulist.size() > 0) {
                    tname = ulist.get(0).getName();
                }

                /** 循环遍历返回的结果，数据库中存在的更新，不存在的插入 */
                if (jsonArr != null && jsonArr.size() > 0) {
                    for (int i = 0; i < jsonArr.size(); i++) {
                        // 获取每个人员信息对象
                        JSONObject jsonObject = jsonArr.getJSONObject(i);
                        // 员工ID
                        String enginner_id = jsonObject.getString("enginner_id") == null ? ""
                                : jsonObject.getString("enginner_id");
                        // 员工姓名
                        String NAME = jsonObject.getString("NAME") == null ? "" : jsonObject.getString("NAME");
                        // 工程师SAP Code
                        String sapcode =
                                jsonObject.getString("sapcode") == null ? "" : jsonObject.getString("sapcode");
                        User user = new User();
                        user.setEnginnerId(Long.parseLong(enginner_id));
                        List<User> list = userMapper.selectUserList(user);
                        user.setName(NAME);
                        user.setSapcode(sapcode);
                        user.setTeamleaderId(TeamleaderId);
                        user.setTeamleaderName(tname);
                        if (list != null && list.size() > 0) {
                            user.setId(list.get(0).getId());
                            user.setUpdateTime(new Date());
                            userMapper.updateUser(user);
                        } else {
                            // WorkDay休假状态  0 上班 1休假-上午 2休假-下午
                            String WorkDay =
                                    jsonObject.getString("WorkDay") == null ? "" : jsonObject.getString("WorkDay");
                            user.setWorkday(WorkDay);

                            user.setCreateTime(new Date());
                            userMapper.insertUser(user);
                        }
                    }
                }

            }
        }
        return new ResponseWithData<>().success().msg("更新成功").code(200);
    }

    @Override
    public JSONObject getFseSkill(String ServiceNoticeId, String TeamleaderId, String InterfaceType,
                                  String instrumentNo) throws Exception {
        /** 调用CC端接口 2.7获取FSE型号技能接口信息 */
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("getFseSkill.asmx/getFseSkillHandle");
//        url.append("&engineer_id=").append(TeamleaderId);
//        url.append("&instrument_no=").append(instrumentNo);
        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("engineer_id", TeamleaderId);
        builder.add("instrument_no", instrumentNo);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.7获取FSE型号技能接口");
        interfaceOperationLog.setInterfaceType(InterfaceType);
        interfaceOperationLog.setServiceNo(ServiceNoticeId);
        interfaceOperationLog.setFseId(TeamleaderId);
        interfaceOperationLog.setInterfaceUrl(url.toString());
//        interfaceOperationLog.setInterfaceRequest(login.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            log.info("调用CC端返回结果：" + interfaceResponseBody);
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        /** 如果调用接口异常直接返回 */
        if ("0".equals(interfaceState)) {
//            return new ResponseWithData().success().msg("查询失败 调用CC端获取FSE型号技能接口发生异常").code(202);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("code", 202);
            jsonObject.put("msg", "查询失败 调用CC端获取FSE型号技能接口发生异常");
            jsonObject.put("data", "");
            return jsonObject;
        }
        JSONObject jsonStr = new JSONObject();
        jsonStr.put("msg", "查询异常");
        jsonStr.put("code", 203);
        if (res != null) {
            if (res.code() == 200) {
                JSONObject obj = JSON.parseObject(interfaceResponseBody);
                if ("1".equals(obj.getString("status"))) {

                    /** 获取CC端获取FSE型号技能接口信息 */
                    jsonStr.put("record", obj.getJSONArray("record"));
                    jsonStr.put("msg", "查询成功");
                    jsonStr.put("code", 200);
                    return jsonStr;
                }
            }
        }
        return jsonStr;
    }

    /**
     * 2.24 电话解决报告
     *
     * @return okhttp3.Response
     * @author yzg
     * @date 2020/3/6 10:08 上午
     */
    @Override
    public String phoneSolveSubmithandle(Map<String, String> params) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("phoneSolveSubmit.asmx/phoneSolveSubmithandle?output=json");

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("电话解决报告");
        interfaceOperationLog.setInterfaceType("phoneSolveSubmithandle");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest(JSON.toJSONString(params));
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        FormBody.Builder builder = new FormBody.Builder();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            builder.add(entry.getKey(), StringUtils.isEmpty(entry.getValue()) ? "" : entry.getValue());
        }

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            log.info("调用CC端返回结果：" + interfaceResponseBody);
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        if (!"1".equals(interfaceState)) {
            return null;
        }

        return interfaceResponseBody;
    }

    /**
     * 2.31 删除服务报告
     *
     * @param enginnerId 工程师id	必须
     * @param serviceNo  服务名称	必须
     * @param reportGuid App端生成唯一的	必须
     * @return okhttp3.Response
     * @author yzg
     * @date 2020/3/6 10:35 上午
     */

    @Override
    public String deleteServiceReport(Long enginnerId, String serviceNo, String reportGuid) {
        //首先跟新CC备件状态为在使用

        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("deleteServiceReport.asmx/deleteServicehandle?output=json");
        url.append("&enginner_id=").append(enginnerId);
        url.append("&Service_no=").append(serviceNo);
        url.append("&report_guid=").append(reportGuid);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("删除服务报告");
        interfaceOperationLog.setInterfaceType("deleteServiceReport");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().getRequest(url.toString(), null);
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();

            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        if (!"1".equals(interfaceState)) {
            return null;
        }

        return interfaceResponseBody;
    }

    /**
     * 2.19	服务关闭-2[安装验收报告] 提交安装验收报告
     *
     * @return okhttp3.Response
     * @author yzg
     * @date 2020/3/7 10:34 上午
     */
    @Override
    public String installReceivingReporthandle(Map<String, String> params) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("InstallReceivingReportSubmit.asmx/InstallReceivingReporthandle?output=json");

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("安装验收报告");
        interfaceOperationLog.setInterfaceType("InstallReceivingReporthandle");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest(JSON.toJSONString(params));
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        FormBody.Builder builder = new FormBody.Builder();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            builder.add(entry.getKey(), StringUtils.isEmpty(entry.getValue()) ? "" : entry.getValue());
        }

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        if (!"1".equals(interfaceState)) {
            return null;
        }

        return interfaceResponseBody;
    }

    /**
     * 2.21	服务关闭-4[Error report] 提交Error report
     *
     * @return okhttp3.Response
     * @author yzg
     * @date 2020/3/7 10:49 上午
     */

    @Override
    public String erroReporthandleerroReportInfo(Map<String, Object> params) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("erroReportSubmit.asmx/erroReporthandleerroReportInfo?output=json");

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("Error report");
        interfaceOperationLog.setInterfaceType("erroReporthandleerroReportInfo");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest(JSON.toJSONString(params));
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        FormBody.Builder builder = new FormBody.Builder();
        for (Map.Entry<String, Object> entry : params.entrySet()) {
            builder.add(entry.getKey(),
                    ObjectUtils.isEmpty(entry.getValue()) ? "" : entry.getValue().toString());
        }

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
            log.info("调用CC端返回结果：" + interfaceResponseBody);
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        if (!"1".equals(interfaceState)) {
            return null;
        }

        return interfaceResponseBody;
    }

    /**
     * 2.22	服务关闭-5[Hot Account  report] 提交Hot Account  report
     *
     * @return okhttp3.Response
     * @author yzg
     * @date 2020/3/7 11:02 上午
     */
    @Override
    public String accountReporthandle(Map<String, String> params) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("hotaccounteportSubmit.asmx/AccountReporthandle?output=json");

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("Hot Account  report");
        interfaceOperationLog.setInterfaceType("AccountReporthandle");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest(JSON.toJSONString(params));
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        FormBody.Builder builder = new FormBody.Builder();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            builder.add(entry.getKey(), StringUtils.isEmpty(entry.getValue()) ? "" : entry.getValue());
        }

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        if (!"1".equals(interfaceState)) {
            return null;
        }

        return interfaceResponseBody;
    }

    /**
     * 2.23	关闭ErrorReport/HT
     *
     * @param service_no  Service号
     * @param enginner_id 提交的工程师ID
     * @param report_guid 唯一主键
     * @param Report_type 报告类型  ER/HT
     * @return okhttp3.Response
     * @author yzg
     * @date 2020/3/7 11:07 上午
     */
    @Override
    public Response closeServicehandle(String service_no, Long enginner_id, String report_guid,
                                       String Report_type) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("closeReport/closeReport.asmx/closeServicehandle?output=json");
        url.append("service_no=").append(service_no);
        url.append("enginner_id=").append(enginner_id);
        url.append("report_guid=").append(report_guid);
        url.append("Report_type=").append(Report_type);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("关闭ErrorReport/HT");
        interfaceOperationLog.setInterfaceType("closeServicehandle");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().getRequest(url.toString(), null);
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        if ("1".equals(interfaceState)) {
            return null;
        }

        return res;
    }

    /**
     * 2.20	服务关闭-3 [安装质量报告]
     *
     * @return okhttp3.Response
     * @author yzg
     * @date 2020/3/7 11:19 上午
     */
    @Override
    public String installqualityReporthandle(Map<String, Object> params) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("InstallqualityReportSubmit.asmx/InstallqualityReporthandle");

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.20服务关闭-3 [安装质量报告] ");
        interfaceOperationLog.setInterfaceType("InstallqualityReporthandle");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest(JSON.toJSONString(params));
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        FormBody.Builder builder = new FormBody.Builder();
        for (Map.Entry<String, Object> entry : params.entrySet()) {
            builder.add(entry.getKey(),
                    ObjectUtils.isEmpty(entry.getValue()) ? "" : entry.getValue().toString());
        }

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        if (!"1".equals(interfaceState)) {
            return null;
        }

        return interfaceResponseBody;
    }

    /**
     * 2.18	服务关闭-1[提交服务报告]
     *
     * @return okhttp3.Response
     * @author yzg
     * @date 2020/3/10 2:44 下午
     */
    @Override
    public String serviceSubmithandle(Map<String, Object> params) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("serviceSubmit.asmx/serviceSubmithandle?output=json");

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("服务报告");
        interfaceOperationLog.setInterfaceType("serviceSubmithandle");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest(JSON.toJSONString(params));
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        FormBody.Builder builder = new FormBody.Builder();
        for (Map.Entry<String, Object> entry : params.entrySet()) {
            builder.add(entry.getKey(), ObjectUtils.isEmpty(entry.getValue()) ? "" : entry.getValue().toString());
        }

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        if (!"1".equals(interfaceState)) {
            return null;
        }

        return interfaceResponseBody;
    }

    @Override
    public ResponseWithData<?> syncTLServiceData(Long timeStamp) throws Exception {

        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("syncTLServiceData.asmx/GetNotificationInfo");
//        url.append("&last_sync_time=").append(timeStamp);

        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("last_sync_time", timeStamp.toString());

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.2同步TL待指派服务信息接口");
        interfaceOperationLog.setInterfaceType("syncTLServiceData");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest(builder.toString());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {

            /** 调用CC端接口 */
            //OkHttpUtils2  设置超时时间5分钟
            res = OkHttpUtils2.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";

            return new ResponseWithData<>().error().msg("同步失败 调用CC端接口发生异常").code(201);
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        if (res.code() == 200) {
            JSONObject obj = JSON.parseObject(interfaceResponseBody);
            if ("1".equals(obj.getString("status"))) {

                /** 获取CC端 */
                JSONArray jsonArray = obj.getJSONArray("record");
                if (jsonArray != null && jsonArray.size() > 0) {
                    for (int i = 0; i < jsonArray.size(); i++) {

                        ServiceNotice serviceNotice = new ServiceNotice();
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                        JSONObject jsonObject = jsonArray.getJSONObject(i);
                        // Service号
                        String service_no = jsonObject.getString("service_no");
                        serviceNotice.setServiceNo(service_no);
                        
                        String serviceEnginner = jsonObject.getString("service_enginner");
                        serviceNotice.setServiceEnginner(serviceEnginner);

                        String designEngineer = jsonObject.getString("DesignEngineer");
                        serviceNotice.setDesignEngineer(designEngineer);
                        
                        /** 通过服务号验证数据库中是否存在 */
                        List<ServiceNotice> serviceNoticeList = serviceNoticeMapper
                                .selectServiceNoticeList(serviceNotice);

                        // 服务状态
                        String service_status = jsonObject.getString("service_status");
                        serviceNotice.setServiceStatus(service_status);

                        // 服务状态是已完成的修改服务单状态为已完成
                        if ("已完成".equals(service_status)) {
                            serviceNotice.setAppState(3L);
                        }

                        // TODO 指派工程师 接口文档中有 返回的接口没有
                        String Fse = jsonObject.getString("Fse") == null ? "" : jsonObject.getString("Fse");
                        if (StringUtils.isNotEmpty(Fse)) {
                            serviceNotice.setFse(Fse);
                        }

                        // Teamleader
                        String teamleader = jsonObject.getString("teamleader");
                        if (StringUtils.isNotEmpty(teamleader)) {
                            serviceNotice.setTeamleaderId(teamleader);
                        }
                        //1 ——CC操作APP不显示0——APP显示
                        String AppIsAccept = jsonObject.getString("AppIsAccept");
                        serviceNotice.setAppIsAccept(AppIsAccept);

                        //是否推送消息
                        boolean canPushMsg = true;
                        if ("保留".equals(service_status) || "1".equals(AppIsAccept)) {
                            canPushMsg = false;
                        }

                        if (serviceNoticeList != null && serviceNoticeList.size() > 0) {
                            serviceNotice.setId(serviceNoticeList.get(0).getId());

                            // 现在同步过来是【保留】状态 直接修改服务单为保留状态     AppIsAccept 1 ——CC操作APP不显示
                            if ("保留".equals(service_status) || "1".equals(AppIsAccept)) {
                                serviceNotice.setDelFlag("2");
                                serviceNoticeMapper.updateServiceNotice(serviceNotice);

                                //更新service_detail 记录保留
                                ServiceDetails serviceDetails2 = new ServiceDetails();
                                serviceDetails2.setDelFlag("2");
                                serviceDetails2.setServiceNo(service_no);
                                //serviceDetails2.setFseId(serviceDetails1.get(b).getFseId());
                                //serviceDetails2.setState(0L);//不修改状态，如果修改状态，保留后再恢复 状态不能继续
                                serviceDetailsMapper.updateDelServiceDetails(serviceDetails2);

                                //PlanDetails 保留
                                PlanDetails planDetails2 = new PlanDetails();
                                planDetails2.setDelFlag("2");
                                planDetails2.setServiceNo(service_no);
                                //planDetails2.setFseId(serviceDetails1.get(b).getFseId());
                                //planDetails2.setState("0");//不修改状态，如果修改状态，保留后再恢复 状态不能继续
                                planDetailsMapper.updateDelPlanDetail(planDetails2);

                            } else {
                                // 如果之前这条数据是保留数据
                                if ("2".equals(serviceNoticeList.get(0).getDelFlag())) {
                                    // 现在同步过来不是保留状态 则解除保留
                                    serviceNotice.setDelFlag("0");
                                    serviceNoticeMapper.updateServiceNotice(serviceNotice);
                                }
                            }

                            // 如果数据库存在此服务单，而且新同步过来的状态是“已派单” 需要比对 FSE，缺少的移除，新增的添加，原有删除的回复正常，原有非删除不变
                            if ("已派单".equals(service_status) && StringUtils.isNotEmpty(Fse)) {
                                String[] Fses = Fse.split(",");
                                if (Fses != null && Fses.length > 0) {
                                    // 查询数据库中已经派过人的数据 并且是未删除的数据
                                    ServiceDetails serviceDetails = new ServiceDetails();
                                    serviceDetails.setServiceNo(service_no);
                                    // serviceDetails.setDelFlag("0");//限定后，数据无法恢复？？？
                                    List<ServiceDetails> serviceDetails1 = serviceDetailsMapper
                                            .selectServiceDetailsList(serviceDetails);
                                    // 需要比对
                                    if (serviceDetails1 != null && serviceDetails1.size() > 0) {
                                        // 新增数据
                                        List<String> yList = new ArrayList();
                                        // 删除数据
                                        List<String> nList = new ArrayList();

                                        // 找到需要新增的数据
                                        for (int a = 0; a < Fses.length; a++) {
                                            boolean sign = false;
                                            for (int b = 0; b < serviceDetails1.size(); b++) {
                                                if (Fses[a].equals(serviceDetails1.get(b).getFseId())) {
                                                    sign = true;
                                                    break;
                                                }
                                            }
                                            // 如果没有相同的就是新增的
                                            if (!sign) {
                                                yList.add(Fses[a]);
                                            }
                                        }

                                        // 找到需要删除的数据
                                        for (int a = 0; a < serviceDetails1.size(); a++) {
                                            boolean sign = false;
                                            for (int b = 0; b < Fses.length; b++) {
                                                if (serviceDetails1.get(a).getFseId().equals(Fses[b])) {
                                                    sign = true;
                                                    break;
                                                }
                                            }
                                            if (!sign) {
                                                nList.add(serviceDetails1.get(a).getFseId());
                                            }
                                        }

                                        //1、本地存在，更新状态为【正常】
                                        for (int a = 0; a < Fses.length; a++) {
                                            for (int b = 0; b < serviceDetails1.size(); b++) {
                                                if (Fses[a].equals(serviceDetails1.get(b).getFseId())) {

                                                    //if ("2".equals(serviceDetails1.get(b).getDelFlag())) {
                                                    ServiceDetails serviceDetails2 = new ServiceDetails();
                                                    serviceDetails2.setDelFlag("0");
                                                    serviceDetails2.setServiceNo(service_no);
                                                    serviceDetails2.setFseId(serviceDetails1.get(b).getFseId());
                                                    //如果原来是已拒绝6 更新为待接受状态 0
                                                    if ("6".equals(serviceNoticeList.get(0).getDelFlag())) {
                                                        serviceDetails2.setState(0L);
                                                    }
                                                    serviceDetailsMapper.updateDelServiceDetails(serviceDetails2);

                                                    PlanDetails planDetails2 = new PlanDetails();
                                                    planDetails2.setDelFlag("0");
                                                    planDetails2.setServiceNo(service_no);
                                                    planDetails2.setFseId(serviceDetails1.get(b).getFseId());
                                                    //如果原来是已拒绝6 更新为待接受状态 0
                                                    if ("6".equals(serviceNoticeList.get(0).getDelFlag())) {
                                                        planDetails2.setState("0");
                                                    }
                                                    planDetailsMapper.updateDelPlanDetail(planDetails2);
                                                    //}
                                                }
                                            }
                                        }

                                        //2、操作新增数据
                                        if (yList != null && yList.size() > 0) {
                                            // 如果有TL推送，没有不推送
                                            if (StringUtils.isNotEmpty(teamleader)) {
                                                User user1 = new User();
                                                user1.setEnginnerId(Long.parseLong(teamleader));
                                                List<User> users1 = userMapper.selectUserList(user1);
                                                if (users1 != null && users1.size() > 0 && StringUtils
                                                        .isNotEmpty(users1.get(0).getName())) {
                                                    // 调用保存待指派数据方法
                                                    this.insertDaiZhiPai(null, yList, serviceNotice.getId() + "", service_no,
                                                            users1.get(0).getName(), canPushMsg);
                                                }
                                                // 如果没有不推送
                                                else {
                                                    // 调用保存待指派数据方法
                                                    this.insertDaiZhiPai(null, yList, serviceNotice.getId() + "", service_no,
                                                            null, canPushMsg);
                                                }
                                            }
                                            // 没有Tl不推送
                                            else {
                                                // 调用保存待指派数据方法
                                                this.insertDaiZhiPai(null, yList, serviceNotice.getId() + "", service_no,
                                                        null, canPushMsg);
                                            }
                                        }

                                        //3、操作删除数据
                                        if (nList != null && nList.size() > 0) {
                                            for (String s : nList) {
                                                ServiceDetails serviceDetails2 = new ServiceDetails();
                                                serviceDetails2.setDelFlag("2");
                                                serviceDetails2.setServiceNo(service_no);
                                                serviceDetails2.setFseId(s);
                                                //serviceDetails2.setState(0L);//不修改状态，如果修改状态，保留后再恢复 状态不能继续
                                                serviceDetailsMapper.updateDelServiceDetails(serviceDetails2);

                                                PlanDetails planDetails2 = new PlanDetails();
                                                planDetails2.setDelFlag("2");
                                                planDetails2.setServiceNo(service_no);
                                                planDetails2.setFseId(s);
                                                //planDetails2.setState("0");//不修改状态，如果修改状态，保留后再恢复 状态不能继续
                                                planDetailsMapper.updateDelPlanDetail(planDetails2);
                                            }
                                        }
                                    }
                                    // 不需要比对
                                    else {
                                        // 都是新增 直接入库
                                        if (StringUtils.isNotEmpty(teamleader)) {
                                            User user1 = new User();
                                            user1.setEnginnerId(Long.parseLong(teamleader));
                                            List<User> users1 = userMapper.selectUserList(user1);
                                            if (users1 != null && users1.size() > 0 && StringUtils
                                                    .isNotEmpty(users1.get(0).getName())) {
                                                // 调用保存待指派数据方法
                                                this.insertDaiZhiPai(Fses, null, serviceNotice.getId() + "", service_no,
                                                        users1.get(0).getName(), canPushMsg);
                                            }
                                            // 如果没有不推送
                                            else {
                                                // 调用保存待指派数据方法
                                                this.insertDaiZhiPai(Fses, null, serviceNotice.getId() + "", service_no,
                                                        null, canPushMsg);
                                            }
                                        }
                                        // 没有Tl不推送
                                        else {
                                            // 调用保存待指派数据方法
                                            this.insertDaiZhiPai(Fses, null, serviceNotice.getId() + "", service_no,
                                                    null, canPushMsg);
                                        }
                                    }
                                }
                            }

                        } else {
                            // 新增 服务单数据
                            serviceNotice.setAppState(1L);
                            serviceNotice.setRecordTime(new Date());
                            serviceNoticeMapper.insertServiceNotice(serviceNotice);

                            /**-------------------- TL新服务单消息推送 ---------------------------------------*/
                            // 只有有TL的已派单新数据给FSE做推送
                            if (StringUtils.isNotEmpty(teamleader)) {
                                User user1 = new User();
                                user1.setEnginnerId(Long.parseLong(teamleader));
                                List<User> users1 = userMapper.selectUserList(user1);
                                if (users1 != null && users1.size() > 0 && StringUtils
                                        .isNotEmpty(users1.get(0).getRegistrationId())) {

                                    // 如果是TL派单 给TL发送推送
                                    if ("TL派单".equals(service_status)) {
                                        // 调用TL推送
                                        this.pushTeamleader(serviceNotice.getId() + "", service_no, teamleader,
                                                users1.get(0).getRegistrationId());
                                    }

                                    // 验证服务单是已经指派过的
                                    if ("已派单".equals(service_status) && StringUtils.isNotEmpty(Fse)) {
                                        String[] Fses = Fse.split(",");
                                        // 如果有TL推送
                                        if (StringUtils.isNotEmpty(users1.get(0).getName())) {
                                            // 调用保存待指派数据方法
                                            this.insertDaiZhiPai(Fses, null, serviceNotice.getId() + "", service_no,
                                                    users1.get(0).getName(), canPushMsg);
                                        }
                                        // 如果没有不推送
                                        else {
                                            // 调用保存待指派数据方法
                                            this.insertDaiZhiPai(Fses, null, serviceNotice.getId() + "", service_no,
                                                    null, canPushMsg);
                                        }
                                    }

                                }
                            }
                            // 没有Tl不推送
                            else {
                                if ("已派单".equals(service_status) && StringUtils.isNotEmpty(Fse)) {
                                    String[] Fses = Fse.split(",");
                                    // 调用保存待指派数据方法
                                    //  this.insertDaiZhiPai(Fses, null, serviceNotice.getId()+"", service_no, null);
                                    this.insertDaiZhiPai(Fses, null, serviceNotice.getId() + "", service_no,
                                            serviceEnginner, canPushMsg);
                                }
                            }
                        }

                        // 联系人
                        String contact = jsonObject.getString("contact");
                        serviceNotice.setContact(contact);

                        // 用户名称
                        String customer_name = jsonObject.getString("customer_name");
                        serviceNotice.setCustomerName(customer_name);

                        // 用户英文名称
                        String customer_enname = jsonObject.getString("customer_enname");
                        serviceNotice.setCustomerEnname(customer_enname);

                        // 电话
                        String telephone = jsonObject.getString("telephone");
                        serviceNotice.setTelephone(telephone);

                        // 客户类型
                        String enginner_type = jsonObject.getString("enginner_type");
                        serviceNotice.setEnginnerType(enginner_type);

                        // 客户类型
                        String userIsDpel = jsonObject.getString("User_IsDpel");
                        serviceNotice.setUserIsdpel(userIsDpel);

                        // 手机
                        String mobile = jsonObject.getString("mobile");
                        serviceNotice.setMobile(mobile);

                        // 电子邮件
                        String email = jsonObject.getString("email");
                        serviceNotice.setEmail(email);

                        // 省份
                        String province = jsonObject.getString("province");
                        serviceNotice.setProvince(province);

                        // 服务合同
                        String service_contract = jsonObject.getString("service_contract") == null ? ""
                                : jsonObject.getString("service_contract");
                        serviceNotice.setServiceContract(service_contract);

                        // 城市
                        String city = jsonObject.getString("city");
                        serviceNotice.setCity(city);

                        // 希望服务时间
                        String hope_business_hours = jsonObject.getString("hope_business_hours");
                        if (StringUtils.isNotEmpty(hope_business_hours)) {
                            if (hope_business_hours.length() == 10) {
                                hope_business_hours += " 00:00:00";
                            }
                            serviceNotice.setHopeBusinessHours(sdf.parse(hope_business_hours));
                        }

                        // 上门地址
                        String home_address = jsonObject.getString("home_address");
                        serviceNotice.setHomeAddress(home_address);

                        // 完备日期
                        String MaturityDate = jsonObject.getString("MaturityDate");
                        serviceNotice.setMaturityDate(sdf.parse(MaturityDate));

                        // 服务类型
                        String service_type = jsonObject.getString("service_type");
                        serviceNotice.setServiceType(service_type);

                        // 子服务类型
                        String sub_service_type = jsonObject.getString("sub_service_type") == null ? ""
                                : jsonObject.getString("sub_service_type");
                        serviceNotice.setSubServiceType(sub_service_type);

                        // 服务级别
                        String service_level = jsonObject.getString("service_level");
                        serviceNotice.setServiceLevel(service_level);

                        // 安装准备确认单
                        String install_confirm_sheet = jsonObject.getString("install_confirm_sheet");
                        serviceNotice.setInstallConfirmSheet(install_confirm_sheet);

                        // 生成时间
                        String create_time = jsonObject.getString("create_time");
                        serviceNotice.setCreateTime(sdf.parse(create_time));

                        // 是否保内
                        String is_warranty = jsonObject.getString("is_warranty");
                        serviceNotice.setIsWarranty(is_warranty);

                        // 邮编
                        String postCode = jsonObject.getString("POSTCODE");
                        serviceNotice.setPostCode(postCode);

                        // 距离上次服务关闭时间
                        Long last_colse_service_time = jsonObject.getLong("last_colse_service_time");
                        if (last_colse_service_time != null) {
                            serviceNotice.setLastColseServiceTime(last_colse_service_time);
                        }

                        // 仪器最后服务关闭时间
                        String machine_last_service_colse_time =
                                jsonObject.getString("machine_last_service_colse_time") == null ? ""
                                        : jsonObject.getString("machine_last_service_colse_time");
                        if (StringUtils.isNotEmpty(machine_last_service_colse_time)) {
                            serviceNotice
                                    .setMachineLastServiceColseTime(sdf.parse(machine_last_service_colse_time));
                        }

                        // 派单人
                        String send_service = jsonObject.getString("send_service");
                        serviceNotice.setSendService(send_service);

                        // 派单时间
                        String Send_time =
                                jsonObject.getString("Send_time") == null ? "" : jsonObject.getString("Send_time");
                        if (StringUtils.isNotEmpty(Send_time)) {
                            if (Send_time.length() == 10) {
                                Send_time += " 00:00:00";
                            }
                            serviceNotice.setSendTime(sdf.parse(Send_time));
                        }

                        // 仪器信息 需要处理
                        String instrument_data = jsonObject.getString("instrument_data");
                        if (StringUtils.isNotEmpty(instrument_data) && !"[]".equals(instrument_data)) {
                            // TODO 解析仪器信息
                            JSONObject instrument_data_json = JSON.parseArray(instrument_data).getJSONObject(0);

                            /** 关联服务单的仪器表 */
                            ServiceInstrument serviceInstrument = new ServiceInstrument();
                            /** 仪器表 */
                            InstrumentInfo instrumentInfo = new InstrumentInfo();

                            serviceInstrument.setServiceNoticeId(serviceNotice.getId());
                            serviceInstrument.setServiceNo(serviceNotice.getServiceNo());

                            List<ServiceInstrument> serviceInstrumentList = serviceInstrumentMapper
                                    .selectServiceInstrumentList(serviceInstrument);

                            // 仪器id
                            String instrument_id = instrument_data_json.getString("instrument_id");
                            serviceInstrument.setInstrumentId(instrument_id);
                            instrumentInfo.setInstrumentId(instrument_id);

                            List<InstrumentInfo> instrumentInfoList = instrumentInfoMapper
                                    .selectInstrumentInfoList(instrumentInfo);

                            // 仪器型号
                            String instrument_no = instrument_data_json.getString("instrument_no");
                            serviceInstrument.setInstrumentNo(instrument_no);

                            // 仪器序列号
                            String instrument_serial_number = instrument_data_json
                                    .getString("instrument_serial_number");
                            serviceInstrument.setInstrumentSerialNumber(instrument_serial_number);
                            instrumentInfo.setInstSn(instrument_serial_number);

                            // factory So
                            String factory_so = instrument_data_json.getString("factory_so");
                            serviceInstrument.setFactorySo(factory_so);

                            // 发货时间
                            String delivery_time = instrument_data_json.getString("delivery_time");
                            if (StringUtils.isNotEmpty(delivery_time)) {
                                serviceInstrument.setDeliveryTime(sdf.parse(delivery_time));
                            }

                            // 保修开始时间
                            String guarantee_start_time = instrument_data_json.getString("guarantee_start_time");
                            if (StringUtils.isNotEmpty(guarantee_start_time)) {
                                serviceInstrument.setGuaranteeStartTime(sdf.parse(guarantee_start_time));
                            }

                            // 保修结束时间
                            String guarantee_end_time = instrument_data_json.getString("guarantee_end_time");
                            if (StringUtils.isNotEmpty(guarantee_end_time)) {
                                serviceInstrument.setGuaranteeEndTime(sdf.parse(guarantee_end_time));
                            }

                            // 合同
                            String contract = instrument_data_json.getString("contract");
                            serviceInstrument.setContract(contract);

                            // 备件
                            String part = instrument_data_json.getString("part");
                            serviceInstrument.setPart(part);

                            // SLA
                            String sla = instrument_data_json.getString("sla") == null ? ""
                                    : instrument_data_json.getString("sla");
                            serviceInstrument.setSla(sla);

                            // 备注
                            String instrument_remark = instrument_data_json.getString("instrument_remark");
                            serviceInstrument.setInstrumentRemark(instrument_remark);

                            // 仪器类型
                            String instrument_type = instrument_data_json.getString("instrument_type");
                            serviceInstrument.setInstrumentType(instrument_type);

                            // 仪器状态
                            String instrument_status = instrument_data_json.getString("instrument_status");
                            serviceInstrument.setInstrumentStatus(instrument_status);

                            // 状态备注
                            String Status_remark = instrument_data_json.getString("Status_remark");
                            serviceInstrument.setStatusRemark(Status_remark);

                            // Materialcode
                            String Materialcode = instrument_data_json.getString("Materialcode");
                            serviceInstrument.setMaterialcode(Materialcode);

                            // lifecycle
                            String lifecycle = instrument_data_json.getString("lifecycle");
                            serviceInstrument.setLifecycle(lifecycle);

                            // 品牌
                            String brand = instrument_data_json.getString("Brand");
                            serviceInstrument.setBrand(brand);

                            // 约定服务范围
                            String ServiceRange = instrument_data_json.getString("ServiceRange");
                            serviceInstrument.setServiceRange(ServiceRange);

                            // DEVI-BU
                            String divi_bu = instrument_data_json.getString("divi_bu");
                            serviceInstrument.setDiviBu(divi_bu);

                            // 安装地址
                            String InsAddress = instrument_data_json.getString("InsAddress");
                            instrumentInfo.setInstAddress(InsAddress);

                            // MD标识
                            String mdsign = instrument_data_json.getString("mdsign");
                            serviceInstrument.setMdsign(mdsign);

                            // 验收报告需求
                            String acceptrequest = instrument_data_json.getString("acceptrequest") == null ? ""
                                    : instrument_data_json.getString("acceptrequest");
                            serviceInstrument.setAcceptrequest(acceptrequest);

                            // MD标识
                            String sap_material_no =
                                    instrument_data_json.getString("sap_material_no") == null ? ""
                                            : instrument_data_json.getString("sap_material_no");
                            serviceInstrument.setSapMaterialNo(sap_material_no);

                            // AcountFSE
                            String AcountFSE = instrument_data_json.getString("AcountFSE") == null ? ""
                                    : instrument_data_json.getString("AcountFSE");
                            serviceNotice.setAccoutfseId(AcountFSE);
                            instrumentInfo.setAccoutfseId(AcountFSE);

                            // AcountName
                            String acountName = instrument_data_json.getString("AcountName") == null ? ""
                                    : instrument_data_json.getString("AcountName");
                            serviceNotice.setAccoutfseName(acountName);
                            instrumentInfo.setAccoutfseName(acountName);

                            /** 服务单仪器子表 */
                            if (serviceInstrumentList != null && serviceInstrumentList.size() > 0) {
                                serviceInstrument.setId(serviceInstrumentList.get(0).getId());
                                serviceInstrument.setUpdateTime(new Date());
                                serviceInstrumentMapper.updateSyncServiceInstrument(serviceInstrument);
                            } else {
                                serviceInstrument.setCreateTime(new Date());
                                serviceInstrumentMapper.insertServiceInstrument(serviceInstrument);
                            }

                            /** 仪器表 */
                            if (instrumentInfoList != null && instrumentInfoList.size() > 0) {
                                instrumentInfo.setId(instrumentInfoList.get(0).getId());
                                instrumentInfo.setUpdateTime(new Date());
                                instrumentInfoMapper.updateSyncInstrumentInfo(instrumentInfo);
                            } else {

                                /** 调用高德地理解析接口，根据地址解析经纬度 */
                                Map<String, String> map = locationService.AddressResolution(InsAddress, "");
                                if (map != null && map.size() == 2) {
                                    instrumentInfo.setLongitude(Double.parseDouble(map.get("longitude")));
                                    instrumentInfo.setLatitude(Double.parseDouble(map.get("latitude")));
                                }

                                instrumentInfo.setCreateTime(new Date());
                                instrumentInfoMapper.insertInstrumentInfo(instrumentInfo);
                            }

                        }
                        // TODO 备件信息 接口文档中有 返回的接口没有
                        String Part_data = jsonObject.getString("Part_data");
                        if (StringUtils.isNotEmpty(Part_data) && !"[]".equals(Part_data)) {
                            JSONArray Part_data_jsonArray = JSON.parseArray(Part_data);

                            /** 先删除所有备件，然后在新增新的备件 */
                            ServicePart sp = new ServicePart();
                            sp.setServiceNoticeId(serviceNotice.getId());
                            servicePartMapper.deleteServicePart(sp);

                            for (int j = 0; j < Part_data_jsonArray.size(); j++) {
                                JSONObject Part_data_json = Part_data_jsonArray.getJSONObject(j);
                                ServicePart servicePart = new ServicePart();

                                servicePart.setServiceNoticeId(serviceNotice.getId());
                                servicePart.setServiceNo(serviceNotice.getServiceNo());

                                // 备件号
                                String Part_no = Part_data_json.getString("Part_no");
                                servicePart.setPartNo(Part_no);

                                // 备件名称
                                String Part_name = Part_data_json.getString("Part_name");
                                servicePart.setPartName(Part_name);

                                // 序列号
                                String serial_number = Part_data_json.getString("serial_number") == null ? ""
                                        : Part_data_json.getString("serial_number");
                                servicePart.setSerialNumber(serial_number);

                                // 借货单号
                                String Part_DebitNo = Part_data_json.getString("Part_DebitNo") == null ? ""
                                        : Part_data_json.getString("Part_DebitNo");
                                servicePart.setPartDebitNo(Part_DebitNo);

                                // 数量
                                String qty =
                                        Part_data_json.getString("qty") == null ? "" : Part_data_json.getString("qty");
                                servicePart.setQty(qty);

                                // 单价
                                String Price = Part_data_json.getString("Price") == null ? ""
                                        : Part_data_json.getString("Price");
                                servicePart.setPrice(Price);

                                // 总价
                                String TotalPrice = Part_data_json.getString("TotalPrice") == null ? ""
                                        : Part_data_json.getString("TotalPrice");
                                servicePart.setTotalPrice(TotalPrice);

                                // 备注
                                String remark = Part_data_json.getString("remark") == null ? ""
                                        : Part_data_json.getString("remark");
                                servicePart.setRemark(remark);

                                // partremark
                                String partremark = Part_data_json.getString("partremark") == null ? ""
                                        : Part_data_json.getString("partremark");
                                servicePart.setPartremark(partremark);

                                servicePart.setCreateTime(new Date());

                                // 保存服务单关联备件
                                servicePartMapper.insertServicePart(servicePart);

                            }

                        }

                        // 故障描述
                        String trouble_description = jsonObject.getString("trouble_description");
                        serviceNotice.setTroubleDescription(trouble_description);

                        // 备注
                        String remark = jsonObject.getString("remark");
                        serviceNotice.setRemark(remark);

                        // 客户VIP标识
                        String is_vip = jsonObject.getString("is_vip");
                        serviceNotice.setIsVip(is_vip);

                        // 接待人
                        String receiver =
                                jsonObject.getString("receiver") == null ? "" : jsonObject.getString("receiver");
                        serviceNotice.setReceiver(receiver);

                        // 接待人手机
                        String receiver_mobile = jsonObject.getString("receiver_mobile") == null ? ""
                                : jsonObject.getString("receiver_mobile");
                        serviceNotice.setReceiverMobile(receiver_mobile);

                        // 接待人邮箱
                        String receiver_email = jsonObject.getString("receiver_email") == null ? ""
                                : jsonObject.getString("receiver_email");
                        serviceNotice.setReceiverEmail(receiver_email);

                        // 电脑厂家
                        String computer_Mfr = jsonObject.getString("computer_Mfr");
                        serviceNotice.setComputerMfr(computer_Mfr);

                        // 电脑型号
                        String model_number = jsonObject.getString("model_number");
                        serviceNotice.setModelNumber(model_number);

                        // 服务号
                        String service_number = jsonObject.getString("service_number");
                        serviceNotice.setServiceNumber(service_number);

                        // 操作系统
                        String software = jsonObject.getString("software");
                        serviceNotice.setSoftware(software);

                        // 选项软件
                        String option_software = jsonObject.getString("option_software");
                        serviceNotice.setOptionSoftware(option_software);

                        // 系统软件
                        String system_software = jsonObject.getString("system_software");
                        serviceNotice.setSystemSoftware(system_software);

                        // 培训名额
                        String train_quota = jsonObject.getString("train_quota");
                        serviceNotice.setTrainQuota(train_quota);

                        // 仪器类型
                        String producttype = jsonObject.getString("producttype") == null ? ""
                                : jsonObject.getString("producttype");
                        serviceNotice.setProducttype(producttype);

                        // 合同信息
                        String contract_info = jsonObject.getString("contract_info");
                        serviceNotice.setContractInfo(contract_info);

                        // TODO arrive_time、service_enginner、appoint_time 字段接口文档中没有 返回值有

                        // 服务关闭时间
                        String close_time = jsonObject.getString("close_time");
                        if (StringUtils.isNotEmpty(close_time)) {
                            if (close_time.length() == 16) {
                                close_time += ":00";
                            }
                            serviceNotice.setCloseTime(sdf.parse(close_time));
                        }

                        // 仪器安装时间
                        String installation_date = jsonObject.getString("installation_date");
                        if (StringUtils.isNotEmpty(installation_date)) {
                            if (installation_date.length() == 10) {
                                installation_date += " 00:00:00";
                            }
                            serviceNotice.setInstallationDate(sdf.parse(installation_date));
                        }

                        // CFDA
                        String CFDA = jsonObject.getString("CFDA");
                        serviceNotice.setCfda(CFDA);

                        //AppRemark APP不可操作原因
                        String AppRemark = jsonObject.getString("AppRemark");
                        serviceNotice.setAppRemark(AppRemark);

                        //SAP服务号
                        String Sap_SnNO = jsonObject.getString("Sap_SnNO");
                        serviceNotice.setSapSnno(Sap_SnNO);

                        /** 服务单主表 如果存在更新，如果不存在新增 */
                        serviceNoticeMapper.updateSyncServiceNotice(serviceNotice);

                        // 现在同步过来是【保留】状态 直接修改服务单为保留状态     AppIsAccept 1 ——CC操作APP不显示
                        if ("保留".equals(service_status) || "1".equals(AppIsAccept)) {
                            serviceNotice.setDelFlag("2");
                            serviceNoticeMapper.updateServiceNotice(serviceNotice);

                            //更新service_detail 记录保留
                            ServiceDetails serviceDetails2 = new ServiceDetails();
                            serviceDetails2.setDelFlag("2");
                            serviceDetails2.setServiceNo(service_no);
                            //serviceDetails2.setFseId(serviceDetails1.get(b).getFseId());
                            //serviceDetails2.setState(0L);//不修改状态，如果修改状态，保留后再恢复 状态不能继续
                            serviceDetailsMapper.updateDelServiceDetails(serviceDetails2);

                            //PlanDetails 保留
                            PlanDetails planDetails2 = new PlanDetails();
                            planDetails2.setDelFlag("2");
                            planDetails2.setServiceNo(service_no);
                            //planDetails2.setFseId(serviceDetails1.get(b).getFseId());
                            //planDetails2.setState("0");//不修改状态，如果修改状态，保留后再恢复 状态不能继续
                            planDetailsMapper.updateDelPlanDetail(planDetails2);
                        }
                    }

                    return new ResponseWithData().success().msg("同步成功").code(200);
                }
            } else if ("2".equals(obj.getString("status"))) {
                //无数据
                return new ResponseWithData().success().msg("同步成功").code(200);
            }
        }

        return new ResponseWithData<>().error().msg("同步失败").code(201);
    }

    /**
     * TL消息推送
     *
     * @methodName: pushTeamleader
     * @description: TODO
     * @return: void
     * @author: shihx
     * @date: 2020-04-20 13:24
     **/
    public void pushTeamleader(String serviceNoticeId, String serviceNo, String teamleaderId,
                               String registrationId) {
        // 推送额外参数
        JsonObject extra = new JsonObject();
        extra.addProperty("type", PushConfig.DISPATCHED_WORKER_STATE);
        extra.addProperty("serviceNoticeId", serviceNoticeId);
        extra.addProperty("serviceNo", serviceNo);
        extra.addProperty("teamleaderId", teamleaderId);

        JpushLog jpushLog = new JpushLog();
        PushResult pushResult = null;
        try {
            JPushClientUtil.getInstance()
                    .initJPushClient(jPushConfig.getSecret(), jPushConfig.getAppkey());
            pushResult = JPushClientUtil.getInstance()
                    .sendPush(registrationId, PushConfig.DISPATCHED_WORKER_TITLE,
                            PushConfig.DISPATCHED_WORKER_CONTENT.replaceAll("NO", serviceNo), extra);

            jpushLog.setStatuscode(pushResult.statusCode + "");
            jpushLog.setMsgId(pushResult.msg_id + "");
            jpushLog.setSendno(pushResult.sendno + "");
        } catch (APIConnectionException e) {
            // Connection error, should retry later
            log.error("Connection error, should retry later", e);
            jpushLog.setMessage("APIConnectionException:" + e.getMessage());
        } catch (APIRequestException e) {
            // Should review the error, and fix the request
            log.error("Should review the error, and fix the request", e);
            log.info("HTTP Status: " + e.getStatus());
            log.info("Error Code: " + e.getErrorCode());
            log.info("Error Message: " + e.getErrorMessage());
            jpushLog.setStatuscode(e.getErrorCode() + "");
            jpushLog.setMessage(e.getStatus() + "," + e.getErrorMessage());
        }
        // 保存推送日志
        jpushLog.setEnginnerId(teamleaderId);
        jpushLog.setType(PushConfig.ONE_PUSH);
        jpushLog.setRegistrationId(registrationId);
        jpushLog.setState(PushConfig.DISPATCHED_WORKER_STATE);
        jpushLog.setNoticeId(Long.parseLong(serviceNoticeId));
        jpushLog.setServiceNo(serviceNo);
        jpushLog.setTitle(PushConfig.DISPATCHED_WORKER_TITLE);
        jpushLog.setContent(PushConfig.DISPATCHED_WORKER_CONTENT.replaceAll("NO", serviceNo));
        jpushLog.setExtra(extra.toString());
        jpushLog.setPushTime(new Date());
        jpushLog.setCreateTime(new Date());
        jpushLogMapper.insertJpushLog(jpushLog);
    }

    /**
     * 待接受消息推送
     *
     * @methodName: pushDaiJieShou
     * @description: TODO
     * @return: void
     * @author: shihx
     * @date: 2020-04-20 16:31
     **/
    public void pushDaiJieShou(String serviceNoticeId, String serviceNo, String fse,
                               String registrationId, String planId, String teamleaderName) {
        ServiceNotice serviceNotic = new ServiceNotice();
        serviceNotic.setServiceNo(serviceNo);
        List<ServiceNotice> serviceNoticeList = serviceNoticeMapper.selectServiceNoticeList(serviceNotic);
        if (serviceNoticeList.size() > 0) {
            ServiceNotice serviceNotice = serviceNoticeList.get(0);
            if (serviceNotice.getTeamleaderId() != null) {

                String content = PushConfig.ACCEPT_CONTENT.replaceAll("NAME", teamleaderName).replaceAll("NO", serviceNo);
                // 推送额外参数
                JsonObject extra1 = new JsonObject();
                extra1.addProperty("type", PushConfig.ACCEPT_STATE);
                extra1.addProperty("serviceNoticeId", serviceNoticeId);
                extra1.addProperty("serviceNo", serviceNo);
                extra1.addProperty("planId", planId);

                JpushLog jpushLog1 = new JpushLog();
                PushResult pushResult1 = null;
                try {
                    JPushClientUtil.getInstance()
                            .initJPushClient(jPushConfig.getSecret(), jPushConfig.getAppkey());
                    pushResult1 = JPushClientUtil.getInstance()
                            .sendPush(registrationId, PushConfig.ACCEPT_TITLE, content, extra1);
                    System.out.println(pushResult1);
                    jpushLog1.setStatuscode(pushResult1.statusCode + "");
                    jpushLog1.setMsgId(pushResult1.msg_id + "");
                    jpushLog1.setSendno(pushResult1.sendno + "");
                } catch (APIConnectionException e) {
                    // Connection error, should retry later
                    log.error("Connection error, should retry later", e);
                    jpushLog1.setMessage("APIConnectionException:" + e.getMessage());
                } catch (APIRequestException e) {
                    // Should review the error, and fix the request
                    log.error("Should review the error, and fix the request", e);
                    log.info("HTTP Status: " + e.getStatus());
                    log.info("Error Code: " + e.getErrorCode());
                    log.info("Error Message: " + e.getErrorMessage());
                    jpushLog1.setStatuscode(e.getErrorCode() + "");
                    jpushLog1.setMessage(e.getStatus() + "," + e.getErrorMessage());
                }
                // 保存推送日志
                jpushLog1.setEnginnerId(fse);
                jpushLog1.setType(PushConfig.ONE_PUSH);
                jpushLog1.setRegistrationId(registrationId);
                jpushLog1.setState(PushConfig.ACCEPT_STATE);
                jpushLog1.setNoticeId(Long.parseLong(serviceNoticeId));
                jpushLog1.setServiceNo(serviceNo);
                jpushLog1.setPlanId(Long.parseLong(planId));
                jpushLog1.setTitle(PushConfig.ACCEPT_TITLE);
                jpushLog1.setContent(content);
                jpushLog1.setExtra(extra1.toString());
                jpushLog1.setPushTime(new Date());
                jpushLog1.setCreateTime(new Date());
                jpushLogMapper.insertJpushLog(jpushLog1);
            }

        }


    }

    public void insertDaiZhiPai(String[] Fses, List<String> list, String serviceNoticeId,
                                String serviceNo, String teamleaderName, boolean canPushMsg) {
        if (Fses != null && Fses.length > 0) {
            for (String fse : Fses) {
                // TODO 有指派的人生成派单数据
                if (StringUtils.isNotEmpty(fse)) {

                    // 验证数据库中是否存在数据
                    ServiceDetails serviceDetails1 = new ServiceDetails();
                    serviceDetails1.setServiceNo(serviceNo);
                    serviceDetails1.setFseId(fse);
                    List<ServiceDetails> serviceDetailsList = serviceDetailsMapper
                            .selectServiceDetailsList(serviceDetails1);
                    // 如果存在按照恢复处理
                    if (serviceDetailsList != null && serviceDetailsList.size() > 0) {
                        ServiceDetails serviceDetails2 = new ServiceDetails();
                        serviceDetails2.setDelFlag("0");
                        serviceDetails2.setServiceNo(serviceNo);
                        serviceDetails2.setFseId(fse);
                        serviceDetailsMapper.updateDelServiceDetails(serviceDetails2);

                        PlanDetails planDetails2 = new PlanDetails();
                        planDetails2.setDelFlag("0");
                        planDetails2.setServiceNo(serviceNo);
                        planDetails2.setFseId(fse);
                        planDetailsMapper.updateDelPlanDetail(planDetails2);
                        continue;
                    }

                    User user = new User();
                    user.setEnginnerId(Long.parseLong(fse));
                    List<User> users = userMapper.selectUserList(user);
                    PlanDetails planDetails = new PlanDetails();
                    ServiceDetails serviceDetails = new ServiceDetails();
                    if (users != null && users.size() > 0) {
                        planDetails.setFseName(users.get(0).getName());
                        serviceDetails.setFseName(users.get(0).getName());

                        planDetails.setServiceNoticeId(Long.parseLong(serviceNoticeId));
                        planDetails.setServiceNo(serviceNo);
                        planDetails.setFseId(fse);
                        planDetails.setIsAccept("2");
                        planDetails.setState("0");
                        planDetails.setDelFlag("0");
                        planDetails.setCreateTime(new Date());
                        planDetailsMapper.insertStPlanDetails(planDetails);

                        serviceDetails.setServiceNoticeId(Long.parseLong(serviceNoticeId));
                        serviceDetails.setServiceNo(serviceNo);
                        serviceDetails.setFseId(fse);
                        serviceDetails.setState(0L);
                        serviceDetails.setDelFlag("0");
                        serviceDetails.setCreateTime(new Date());
                        serviceDetails.setUpdateBy(planDetails.getId() + "");
                        serviceDetailsMapper.insertServiceDetails(serviceDetails);

                        if (canPushMsg) {
                            // TODO 如果推送标识有值 推送给TL
                            if (StringUtils.isNotEmpty(teamleaderName) && StringUtils
                                    .isNotEmpty(users.get(0).getRegistrationId())) {
                                // fse 待接受推送
                                this.pushDaiJieShou(serviceNoticeId, serviceNo, fse,
                                        users.get(0).getRegistrationId(),
                                        planDetails.getId() + "", teamleaderName);
                            }
                        }
                    } else {
                        //本地表没有当前fse 存入数据 不推送
                        planDetails.setServiceNoticeId(Long.parseLong(serviceNoticeId));
                        planDetails.setServiceNo(serviceNo);
                        planDetails.setFseId(fse);
                        planDetails.setIsAccept("2");
                        planDetails.setState("0");
                        planDetails.setDelFlag("0");
                        planDetails.setCreateTime(new Date());
                        planDetailsMapper.insertStPlanDetails(planDetails);

                        serviceDetails.setServiceNoticeId(Long.parseLong(serviceNoticeId));
                        serviceDetails.setServiceNo(serviceNo);
                        serviceDetails.setFseId(fse);
                        serviceDetails.setState(0L);
                        serviceDetails.setDelFlag("0");
                        serviceDetails.setCreateTime(new Date());
                        serviceDetails.setUpdateBy(planDetails.getId() + "");
                        serviceDetailsMapper.insertServiceDetails(serviceDetails);
                    }
                }
            }
        }
        if (list != null && list.size() > 0) {
            for (String fse : list) {

                // 验证数据库中是否存在数据
                ServiceDetails serviceDetails1 = new ServiceDetails();
                serviceDetails1.setServiceNo(serviceNo);
                serviceDetails1.setFseId(fse);
                List<ServiceDetails> serviceDetailsList = serviceDetailsMapper
                        .selectServiceDetailsList(serviceDetails1);
                // 如果存在按照恢复处理
                if (serviceDetailsList != null && serviceDetailsList.size() > 0) {
                    ServiceDetails serviceDetails2 = new ServiceDetails();
                    serviceDetails2.setDelFlag("0");
                    serviceDetails2.setServiceNo(serviceNo);
                    serviceDetails2.setFseId(fse);
                    serviceDetailsMapper.updateDelServiceDetails(serviceDetails2);

                    PlanDetails planDetails2 = new PlanDetails();
                    planDetails2.setDelFlag("0");
                    planDetails2.setServiceNo(serviceNo);
                    planDetails2.setFseId(fse);
                    planDetailsMapper.updateDelPlanDetail(planDetails2);
                    continue;
                }

                User user = new User();
                user.setEnginnerId(Long.parseLong(fse));
                List<User> users = userMapper.selectUserList(user);
                PlanDetails planDetails = new PlanDetails();
                ServiceDetails serviceDetails = new ServiceDetails();
                if (users != null && users.size() > 0) {
                    planDetails.setFseName(users.get(0).getName());
                    serviceDetails.setFseName(users.get(0).getName());

                    planDetails.setServiceNoticeId(Long.parseLong(serviceNoticeId));
                    planDetails.setServiceNo(serviceNo);
                    planDetails.setFseId(fse);
                    planDetails.setIsAccept("2");
                    planDetails.setState("0");
                    planDetails.setDelFlag("0");
                    planDetails.setCreateTime(new Date());
                    planDetailsMapper.insertStPlanDetails(planDetails);

                    serviceDetails.setServiceNoticeId(Long.parseLong(serviceNoticeId));
                    serviceDetails.setServiceNo(serviceNo);
                    serviceDetails.setFseId(fse);
                    serviceDetails.setState(0L);
                    serviceDetails.setDelFlag("0");
                    serviceDetails.setCreateTime(new Date());
                    serviceDetails.setUpdateBy(planDetails.getId() + "");
                    serviceDetailsMapper.insertServiceDetails(serviceDetails);

                    if (canPushMsg) {
                        // TODO 如果推送标识有值 推送给TL
                        if (StringUtils.isNotEmpty(teamleaderName) && StringUtils
                                .isNotEmpty(users.get(0).getRegistrationId())) {
                            // fse 待接受推送
                            this.pushDaiJieShou(serviceNoticeId, serviceNo, fse, users.get(0).getRegistrationId(),
                                    planDetails.getId() + "", teamleaderName);
                        }
                    }
                } else {
                    planDetails.setServiceNoticeId(Long.parseLong(serviceNoticeId));
                    planDetails.setServiceNo(serviceNo);
                    planDetails.setFseId(fse);
                    planDetails.setIsAccept("2");
                    planDetails.setState("0");
                    planDetails.setDelFlag("0");
                    planDetails.setCreateTime(new Date());
                    planDetailsMapper.insertStPlanDetails(planDetails);

                    serviceDetails.setServiceNoticeId(Long.parseLong(serviceNoticeId));
                    serviceDetails.setServiceNo(serviceNo);
                    serviceDetails.setFseId(fse);
                    serviceDetails.setState(0L);
                    serviceDetails.setDelFlag("0");
                    serviceDetails.setCreateTime(new Date());
                    serviceDetails.setUpdateBy(planDetails.getId() + "");
                    serviceDetailsMapper.insertServiceDetails(serviceDetails);
                }
            }
        }
    }

    /**
     * 2.27	同步基础数据接口
     */
    @Override
    public List getParamTables(String tableName, Long engineerId) {
        Map<String, String> params = new HashMap<>();
        params.put("engineer_id", engineerId + "");
        params.put("last_sync_time", System.currentTimeMillis() + "");
        params.put("sync_table_name", tableName);

        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("SyncTables.asmx/GetParamTables?output=json");

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("同步基础数据接口");
        interfaceOperationLog.setInterfaceType("GetParamTables");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest(JSON.toJSONString(params));
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        FormBody.Builder builder = new FormBody.Builder();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            builder.add(entry.getKey(), entry.getValue());
        }

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);
        if (res != null) {
            if (res.code() == 200) {
                try {
                    JSONObject jsonObject = JSONObject.parseObject(interfaceResponseBody);
                    if ("1".equals(jsonObject.get("status"))) {
                        JSONArray array = jsonObject.getJSONArray("record");
                        if (null != array) {
                            List<Object> results = new ArrayList<>();
                            for (int i = 0; i < array.size(); i++) {
                                boolean is_disabled = array.getJSONObject(i).getBooleanValue("is_disabled");
                                if (!is_disabled) {
                                    Map<String, String> result = new HashMap<>();
                                    result.put("value", array.getJSONObject(i).getString("id"));
                                    result.put("text", array.getJSONObject(i).getString("name"));
                                    results.add(result);
                                }
                                if (is_disabled) {
                                    results.add(array.getJSONObject(i));
                                }
                            }
                            return results;
                        }
                    }
                } catch (Exception e) {
                    log.error("getParamTables Exception: ", e);
                    return null;
                }
            }
        }
        return null;
    }

    /**
     * 2.27	同步基础数据接口（SyncTables.asmx/GetParamTablesErr 查询级联数据）
     */
    @Override
    public List selectCCDictWidthParent(String tableName, Long engineerId, String parentValue) {
        Map<String, String> params = new HashMap<>();
        params.put("engineer_id", engineerId + "");
        params.put("last_sync_time", System.currentTimeMillis() + "");
        params.put("sync_table_name", tableName);
        params.put("ParentValue", StringUtils.isEmpty(parentValue) ? "" : parentValue);
        params.put("Err_Code", "");

        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("SyncTables.asmx/GetParamTablesErr?output=json");

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("同步基础数据接口");
        interfaceOperationLog.setInterfaceType("GetParamTables");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest(JSON.toJSONString(params));
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        FormBody.Builder builder = new FormBody.Builder();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            builder.add(entry.getKey(), entry.getValue());
        }

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);
        if (res != null) {
            if (res.code() == 200) {
                try {
                    JSONObject jsonObject = JSONObject.parseObject(interfaceResponseBody);
                    if ("1".equals(jsonObject.get("status"))) {
                        JSONArray array = jsonObject.getJSONArray("record");
                        if (null != array) {
                            List<Map<String, String>> results = new ArrayList<>();
                            for (int i = 0; i < array.size(); i++) {
                                boolean is_disabled = array.getJSONObject(i).getBooleanValue("is_disabled");

                                if (!is_disabled) {
                                    Map<String, String> result = new HashMap<>();
                                    result.put("value", array.getJSONObject(i).getString("id"));
                                    result.put("text", array.getJSONObject(i).getString("name"));

                                    results.add(result);
                                }
                            }
                            return results;
                        }
                    }
                } catch (Exception e) {
                    log.error("selectCCDictWidthParent：" + e);
                    return null;
                }
            }
        }
        return null;
    }

    @Override
    public String getParamTables1(String tableName, Long engineerId) {
        Map<String, String> params = new HashMap<>();
        params.put("engineer_id", engineerId + "");
        params.put("last_sync_time", System.currentTimeMillis() + "");
        params.put("sync_table_name", tableName);

        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("SyncTables.asmx/GetParamTables?output=json");

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("同步基础数据接口");
        interfaceOperationLog.setInterfaceType("GetParamTables");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest(JSON.toJSONString(params));
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        FormBody.Builder builder = new FormBody.Builder();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            builder.add(entry.getKey(), entry.getValue());
        }

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        if (!"1".equals(interfaceState)) {
            return null;
        }

        return interfaceResponseBody;
    }

    @Override
    public JSONObject setPartAccountFSE(String teamleaderId, String serviceNo, String accoutfseId,
                                        String instrumentId) {

        JSONObject jsonObject = new JSONObject();

        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("setPartAccountFSE.asmx/setPartAccountFSEHandle");

        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("teamleader_id", teamleaderId);
        builder.add("service_no", serviceNo);
        builder.add("Accoutfse_id", accoutfseId);
        builder.add("instrument_id", instrumentId);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.5TL设置仪器指定FSE");
        interfaceOperationLog.setInterfaceType("setPartAccountFSE");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest(builder.toString());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {

            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        /** 如果调用接口异常直接返回 */
        if ("0".equals(interfaceState)) {
            System.out.println("同步失败 调用CC端接口发生异常");
            jsonObject.put("code", "201");
            jsonObject.put("msg", "同步失败 调用CC端接口发生异常");
            jsonObject.put("data", "");
            return jsonObject;
        }
        if (res != null) {
            if (res.code() == 200) {
                JSONObject obj = JSON.parseObject(interfaceResponseBody);
                if ("1".equals(obj.getString("status"))) {
                    jsonObject.put("code", "200");
                    jsonObject.put("msg", "设置成功");
                    jsonObject.put("data", "");
                    return jsonObject;
                } else {
                    jsonObject.put("code", "203");
                    jsonObject.put("msg", "CC端设置失败");
                    jsonObject.put("data", "");
                    return jsonObject;
                }
            }
        }
        jsonObject.put("code", "202");
        jsonObject.put("msg", "同步失败 接口发生异常");
        jsonObject.put("data", "");
        return jsonObject;
    }

    @Override
    public JSONObject BindDeviceInfo(String instrumentId, String enginnerId, String code) {

        JSONObject jsonObject = new JSONObject();

        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("BindDeviceInfo.asmx/BindDeviceInfoHandle");

        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("instrument_id", instrumentId);
        builder.add("enginner_id", enginnerId);
        builder.add("Code", code);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.17绑定仪器条码");
        interfaceOperationLog.setInterfaceType("BindDeviceInfo");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest(builder.toString());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {

            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            JSONObject obj = JSON.parseObject(interfaceResponseBody);
            jsonObject.put("msg", obj.get("message"));
            jsonObject.put("data", "");
            jsonObject.put("code", res.code());
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            jsonObject.put("code", "201");
            jsonObject.put("msg", "同步失败 调用CC端接口发生异常");
            jsonObject.put("data", "");
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        return jsonObject;
    }

    @Override
    public JSONObject updateOrderInfo(String enginnerId, String serviceNo, String remarks) {
        JSONObject jsonObject = new JSONObject();

        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("updateOrderInfo.asmx/updateOrderInfoHandle");

        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("enginner_id", enginnerId);
        builder.add("service_no", serviceNo);
        builder.add("Remarks", remarks);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.16信息修改申请");
        interfaceOperationLog.setInterfaceType("updateOrderInfo");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest(builder.toString());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {

            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        /** 如果调用接口异常直接返回 */
        if ("0".equals(interfaceState)) {
            jsonObject.put("code", "201");
            jsonObject.put("msg", "同步失败 调用CC端接口发生异常");
            jsonObject.put("data", "");
            return jsonObject;
        }
        if (res != null) {
            if (res.code() == 200) {
                JSONObject obj = JSON.parseObject(interfaceResponseBody);
                if ("1".equals(obj.getString("status"))) {
                    jsonObject.put("code", "200");
                    jsonObject.put("msg", "申请成功");
                    jsonObject
                            .put("data", obj.getJSONArray("record").getJSONObject(0).getString("request_id"));
                    return jsonObject;
                } else {
                    jsonObject.put("code", "203");
                    jsonObject.put("msg", "CC端申请失败");
                    jsonObject.put("data", "");
                    return jsonObject;
                }
            }
        }
        jsonObject.put("code", "202");
        jsonObject.put("msg", "同步失败 接口发生异常");
        jsonObject.put("data", "");
        return jsonObject;
    }


    @Override
    public JSONObject acceptService(String enginnerId, String serviceNo, String expectTime,
                                    String bespokeTime, String sendID, java.util.Date sendDate) {
        JSONObject jsonObject = new JSONObject();

        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("acceptService.asmx/acceptServicehandle");

        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("enginner_id", enginnerId);
        builder.add("service_no", serviceNo);
        builder.add("expect_time", expectTime);
        builder.add("bespoke_time", bespokeTime);
        if (sendID != null) {
            builder.add("send_id", sendID);
        } else {
            builder.add("send_id", "");
        }
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (sendDate != null) {
            builder.add("send_time", sf.format(sendDate));
        } else {
            builder.add("send_time", "");
        }


        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.14接受服务");
        interfaceOperationLog.setInterfaceType("acceptService");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest(builder.toString());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {

            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        /** 如果调用接口异常直接返回 */
        if ("0".equals(interfaceState)) {
            jsonObject.put("code", "201");
            jsonObject.put("msg", "同步失败 调用CC端接口发生异常");
            jsonObject.put("data", "");
            return jsonObject;
        }
        if (res != null) {
            if (res.code() == 200) {
                JSONObject obj = JSON.parseObject(interfaceResponseBody);
                if ("1".equals(obj.getString("status"))) {
                    jsonObject.put("code", "200");
                    jsonObject.put("msg", "接受成功");
                    jsonObject.put("data", "");
                    return jsonObject;
                } else {
                    jsonObject.put("code", "203");
                    jsonObject.put("msg", "CC端接受失败");
                    jsonObject.put("data", "");
                    return jsonObject;
                }
            }
        }
        jsonObject.put("code", "202");
        jsonObject.put("msg", "同步失败 接口发生异常");
        jsonObject.put("data", "");
        return jsonObject;
    }

    @Override
    public JSONObject GetServiceCharge(String engineerId, String bu, String prov, String city) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("GetServiceCharge.asmx/GetServiceCharge");

        FormBody.Builder builder = new FormBody.Builder();
        builder.add("engineer_id", engineerId);
        builder.add("Bu", bu);
        builder.add("Prov", prov);
        builder.add("City", city);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("4、服务费接口");
        interfaceOperationLog.setInterfaceType("GetServiceCharge");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest(builder.toString());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        JSONObject obj = JSON.parseObject(interfaceResponseBody);

        return obj;
    }

    @Override
    public JSONObject getInstrumentList(String CustomerName, String serialNo, String Div, String bu, String starttime, String endtime)
            throws Exception {
        /** 调用CC端接口 2.53查询仪器数据 */
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("syncGetinstrument.asmx/GetinstrumentInfoHandle");
//        url.append("&engineer_id=").append(TeamleaderId);
//        url.append("&instrument_no=").append(instrumentNo);
        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        if (StringUtils.isEmpty(CustomerName)) {
            CustomerName = "";
        }
        if (StringUtils.isEmpty(serialNo)) {
            serialNo = "";
        }
        if (StringUtils.isEmpty(Div)) {
            Div = "";
        }
        if (StringUtils.isEmpty(bu)) {
            bu = "";
        }
        if (StringUtils.isEmpty(starttime)) {
            starttime = "";
        }
        if (StringUtils.isEmpty(endtime)) {
            endtime = "";
        }
        builder.add("CustomerName", CustomerName);
        builder.add("serial_no", serialNo);
        builder.add("Div", Div);
        builder.add("bu", bu);
        builder.add("starttime", starttime);
        builder.add("endtime", endtime);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.53查询仪器数据");
        interfaceOperationLog.setInterfaceType("getInstrumentList");
//        interfaceOperationLog.setServiceNo(ServiceNoticeId);
//        interfaceOperationLog.setFseId(TeamleaderId);
        interfaceOperationLog.setInterfaceUrl(url.toString());
//        interfaceOperationLog.setInterfaceRequest(login.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            log.info("调用CC端返回结果：" + interfaceResponseBody);
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        /** 如果调用接口异常直接返回 */
        if ("0".equals(interfaceState)) {
//            return new ResponseWithData().success().msg("查询失败 调用CC端获取FSE型号技能接口发生异常").code(202);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("code", 202);
            jsonObject.put("msg", "查询失败 调用CC端获取仪器列表接口发生异常");
            jsonObject.put("data", "");
            return jsonObject;
        }
        JSONObject jsonStr = new JSONObject();
        jsonStr.put("msg", "查询异常");
        jsonStr.put("code", 203);
        if (res != null) {
            if (res.code() == 200) {
                JSONObject obj = JSON.parseObject(interfaceResponseBody);
                if ("1".equals(obj.getString("status"))) {

                    /** 获取CC端获取仪器数据接口信息 */
                    JSONArray data = obj.getJSONArray("record");
                    jsonStr.put("msg", "查询成功");
                    jsonStr.put("code", 200);
                    jsonStr.put("data", data);
                    return jsonStr;
                }
            }
        }
        return jsonStr;
    }

    @Override
    public JSONObject closeNotice(String EnginnerId, String serviceNo, Long ServiceNoticeId)
            throws Exception {
        // int noticeNum = planDetailsMapper.selectNoClosedNum(serviceNo, EnginnerId);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        /** 调用CC端接口 2.32 关闭服务通知 */
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("closeService.asmx/closeServicehandle");
        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("enginner_id", EnginnerId);
        builder.add("service_no", serviceNo);
//        builder.add("close_time", sdf.format(new Date()));

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.32 关闭服务通知");
        interfaceOperationLog.setInterfaceType("closeNotice");
        interfaceOperationLog.setServiceNo(serviceNo);
        interfaceOperationLog.setFseId(EnginnerId);
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            log.info("调用CC端返回结果：" + interfaceResponseBody);
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        /** 如果调用接口异常直接返回 */
        if ("0".equals(interfaceState)) {
//            return new ResponseWithData().success().msg("查询失败 调用CC端获取FSE型号技能接口发生异常").code(202);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("code", 202);
            jsonObject.put("msg", "查询失败 调用CC端关闭接口发生异常");
            jsonObject.put("data", "");
            return jsonObject;
        }
        JSONObject obj = JSON.parseObject(interfaceResponseBody);
        JSONObject jsonStr = new JSONObject();
//        if (noticeNum > 0) {
//            jsonStr.put("code", "205");
//            jsonStr.put("message", "未签离不能关闭服务");
//            return jsonStr;
//        }
        jsonStr.put("msg", "关闭异常");
        jsonStr.put("code", 203);
        jsonStr.put("data", obj);
        if (res != null) {
            if (res.code() == 200) {
                if ("1".equals(obj.getString("status"))) {
                    ServiceNotice serviceNotice = new ServiceNotice();
                    serviceNotice.setId(ServiceNoticeId);
                    serviceNotice.setAppState(3L);
                    if(ObjectUtils.isEmpty(serviceNotice.getUpdateDate())){
                        serviceNotice.setUpdateDate(new Date());
                    }
                    serviceNoticeMapper.updateServiceNotice(serviceNotice);
                    /** 获取CC端获取仪器数据接口信息 */
                    JSONArray data = obj.getJSONArray("record");
                    jsonStr.put("msg", "关闭成功");
                    jsonStr.put("code", 200);
                    jsonStr.put("data", obj);
                    return jsonStr;
                }
            }
        }
        return jsonStr;
    }

    @Override
    public JSONObject errorReportCloseNotice(String id, String EnginnerId, String serviceNo, String reportGuid, String reportType)
            throws Exception {
        /** 调用CC端接口 2.23 关闭服务通知 */

        JSONObject jsonStr = new JSONObject();
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("closeReport.asmx/closeServicehandle");
        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("service_no", EnginnerId);
        builder.add("enginner_id", serviceNo);
        builder.add("report_guid", id);
        builder.add("Report_type", reportType);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.23 关闭服务通知");
        interfaceOperationLog.setInterfaceType("closeNotice");
        interfaceOperationLog.setServiceNo(serviceNo);
        interfaceOperationLog.setFseId(EnginnerId);
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            log.info("调用CC端返回结果：" + interfaceResponseBody);

            JSONObject obj = JSON.parseObject(interfaceResponseBody);

            if (res != null) {
                {
                    if (res.code() == 200) {

                        if ("1".equals(obj.getString("status"))) {
                            /** 获取CC端获取仪器数据接口信息 */
                            JSONArray data = obj.getJSONArray("record");
                            jsonStr.put("msg", "关闭成功");
                            jsonStr.put("code", 200);
                            jsonStr.put("data", obj);
                            return jsonStr;
                        } else {
                            /** 获取CC端获取仪器数据接口信息 */
                            JSONArray data = obj.getJSONArray("record");
                            jsonStr.put("msg", "关闭异常");
                            jsonStr.put("code", 201);
                            jsonStr.put("data", obj);
                            return jsonStr;
                        }

                    }

                }

            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
        }
        return jsonStr;
    }


    /**
     * 2.27	同步基础数据接口
     */
    @Override
    public List getErrorCode(Long engineerId) {
        Map<String, String> params = new HashMap<>();
        params.put("engineer_id", engineerId + "");
        params.put("last_sync_time", System.currentTimeMillis() + "");
        params.put("sync_table_name", "error_code");

        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("SyncTables.asmx/GetParamTables?output=json");

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("同步基础数据接口(获取errorCide)");
        interfaceOperationLog.setInterfaceType("GetParamTables");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceType("POST");
        interfaceOperationLog.setInterfaceRequest(JSON.toJSONString(params));
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        FormBody.Builder builder = new FormBody.Builder();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            builder.add(entry.getKey(), entry.getValue());
        }

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);
        if (res != null) {
            if (res.code() == 200) {
                try {
                    JSONObject jsonObject = JSONObject.parseObject(interfaceResponseBody);
                    if ("1".equals(jsonObject.get("status"))) {
                        JSONArray array = jsonObject.getJSONArray("record");
                        if (null != array) {
                            List<Map<String, String>> results = new ArrayList<>();
                            for (int i = 0; i < array.size(); i++) {

                                Map<String, String> result = new HashMap<>();
                                result.put("Err_ResponMan", array.getJSONObject(i).getString("Err_ResponMan"));
                                result.put("Err_CodeTyep", array.getJSONObject(i).getString("Err_CodeTyep"));
                                result.put("Err_Weights", array.getJSONObject(i).getString("Err_Weights"));
                                result.put("ParentValue", array.getJSONObject(i).getString("ParentValue"));
                                result.put("ParentCode", array.getJSONObject(i).getString("ParentCode"));
                                result.put("Err_Value", array.getJSONObject(i).getString("Err_Value"));
                                result.put("Err_LongDESC", array.getJSONObject(i).getString("Err_LongDESC"));
                                result.put("Err_Classifica", array.getJSONObject(i).getString("Err_Classifica"));
                                result.put("Err_Code", array.getJSONObject(i).getString("Err_Code"));
//
                                results.add(result);
                            }
                            return results;
                        }
                    }
                } catch (Exception e) {
                    return null;
                }
            }
        }
        return null;
    }

    @Override
    public JSONObject queryPriceByPartCode(String partCode) throws Exception {
        JSONObject jsonObject = new JSONObject();

        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("QueryPriceByPartCode.asmx/QueryPriceByPartCodeHandle?partcode=");
        url.append(partCode);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.63备件号查询Price及备件名称接口");
        interfaceOperationLog.setInterfaceType("QueryPriceByPartCodeHandle");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {

            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().getRequest(url.toString(), null);
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        jsonObject.put("partcode", partCode);
        jsonObject.put("partname", "");
        jsonObject.put("price", 0.00);

        /** 如果调用接口异常直接返回 */
        if ("0".equals(interfaceState)) {
            log.debug("调用CC端接口发生异常");
            return jsonObject;
        }
        if (res != null) {
            if (res.code() == 200) {
                JSONObject obj = JSON.parseObject(interfaceResponseBody);
                if ("1".equals(obj.getString("status"))) {
                    JSONArray record = obj.getJSONArray("record");
                    if (record != null && record.size() > 0) {
                        jsonObject.put("partcode", record.getJSONObject(0).getString("partcode"));
                        jsonObject.put("partname", record.getJSONObject(0).getString("partname"));
                        jsonObject.put("price", record.getJSONObject(0).getDoubleValue("price"));
                    }

                }
            }
        }
        return jsonObject;
    }


    @Override
    public ResponseWithData<?> getParamTablesErr(String parentValue, String errCode) {

        /** 调用CC端接口 2.27同步基础数据接口 */
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("SyncTables.asmx/GetParamTablesErr");
        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("engineer_id", "");
        builder.add("last_sync_time", "");
        builder.add("sync_table_name", "error_code");
        if (StringUtils.isEmpty(parentValue)) {
            parentValue = "";
        }
        if (StringUtils.isEmpty(errCode)) {
            errCode = "";
        }
        builder.add("ParentValue", parentValue);
        builder.add("Err_Code", errCode);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.27同步基础数据接口-2.27.3请求参数");
        interfaceOperationLog.setInterfaceType("GetParamTablesErr");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog
                .setInterfaceRequest("ParentValue:" + parentValue + ",Err_Code:" + errCode);
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            log.info("调用CC端返回结果：" + interfaceResponseBody);
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        /** 如果调用接口异常直接返回 */
        if ("0".equals(interfaceState)) {
            return new ResponseWithData().error().msg("查询失败 调用CC端接口发生异常").code(202);
        }
        if (res != null) {
            if (res.code() == 200) {
                JSONObject obj = JSON.parseObject(interfaceResponseBody);
                if ("1".equals(obj.getString("status"))) {
                    return new ResponseWithData().success(obj.getJSONArray("record")).msg("查询成功").code(200);
                }
            }
        }
        return new ResponseWithData().error().msg("查询异常").code(203);
    }

    @Override
    public String syncServiceReport(String reportGuid, String serviceNo, String enginnerId) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("syncServiceReport.asmx/GetServiceInfo?output=json");
        url.append("&report_guid=").append(reportGuid);
        url.append("&service_no=").append(serviceNo);
        url.append("&enginner_id=").append(enginnerId);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("同步服务报告数据");
        interfaceOperationLog.setInterfaceType("syncServiceReport");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().getRequest(url.toString(), null);
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        if (!"1".equals(interfaceState)) {
            return null;
        }

        return interfaceResponseBody;
    }

    @Override
    public String syncInstallReceivingReport(String reportGuid, String serviceNo, String enginnerId) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("syncInstallReceivingReport.asmx/GetInstallReceivingReportInfo?output=json");
        url.append("&report_guid=").append(reportGuid);
        url.append("&service_no=").append(serviceNo);
        url.append("&enginner_id=").append(enginnerId);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("同步安装验收数据");
        interfaceOperationLog.setInterfaceType("syncInstallReceivingReport");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().getRequest(url.toString(), null);
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        if (!"1".equals(interfaceState)) {
            return null;
        }

        return interfaceResponseBody;
    }

    @Override
    public String syncInstallqualityReport(String reportGuid, String serviceNo, String enginnerId) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("syncInstallqualityReport.asmx/GetInstallqualityReportInfo?output=json");
        url.append("&report_guid=").append(reportGuid);
        url.append("&service_no=").append(serviceNo);
        url.append("&enginner_id=").append(enginnerId);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("同步安装质量报告数据");
        interfaceOperationLog.setInterfaceType("syncInstallqualityReport");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().getRequest(url.toString(), null);
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        if (!"1".equals(interfaceState)) {
            return null;
        }

        return interfaceResponseBody;
    }

    @Override
    public JSONObject updateFseStateInfo(String enginnerId, String state) throws Exception {
        /** 调用CC端接口 2.53查询仪器数据 */
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("UpdateFseState.asmx/UpdateFseStateInfo");

        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        if (StringUtils.isEmpty(enginnerId)) {
            JSONObject jsonStr = new JSONObject();
            jsonStr.put("msg", "员工ID（enginnerId）不可以为空");
            jsonStr.put("code", 201);
            return jsonStr;
        }
        if (StringUtils.isEmpty(state)) {
            JSONObject jsonStr = new JSONObject();
            jsonStr.put("msg", "休假状态（state）不可以为空");
            jsonStr.put("code", 202);
            return jsonStr;
        }

        builder.add("enginner_id", enginnerId);
        builder.add("State", state);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.65工程师休假状态修改");
        interfaceOperationLog.setInterfaceType("UpdateFseStateInfo");
//        interfaceOperationLog.setServiceNo(ServiceNoticeId);
        interfaceOperationLog.setFseId(enginnerId);
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setInterfaceRequest("enginner_id=" + enginnerId + ",State=" + state);
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            log.info("调用CC端返回结果：" + interfaceResponseBody);
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        /** 如果调用接口异常直接返回 */
        if ("0".equals(interfaceState)) {
//            return new ResponseWithData().success().msg("查询失败 调用CC端获取FSE型号技能接口发生异常").code(202);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("code", 203);
            jsonObject.put("msg", "操作失败 调用CC端接口发生异常");
            jsonObject.put("data", "");
            return jsonObject;
        }
        JSONObject jsonStr = new JSONObject();
        jsonStr.put("msg", "操作异常");
        jsonStr.put("code", 204);
        if (res != null) {
            if (res.code() == 200) {
                JSONObject obj = JSON.parseObject(interfaceResponseBody);
                if ("1".equals(obj.getString("status"))) {
                    jsonStr.put("msg", "操作成功");
                    jsonStr.put("code", 200);
                    jsonStr.put("data", obj);
                    return jsonStr;
                }
            }
        }
        return jsonStr;
    }

    @Override
    public ResponseWithData<?> syncAllServiceReport(String Instrument_id, String starttime,
                                                    String endtime, String CustName, String SnType, String SnSubType, String SerialNo,
                                                    String Status) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("syncAllServiceReport.asmx/GetAllServiceInfoHandle");
        StringBuffer postParam = new StringBuffer();
        postParam.append("Instrument_id=")
                .append(StringUtils.isEmpty(Instrument_id) ? "" : Instrument_id);
        postParam.append("&starttime=").append(StringUtils.isEmpty(starttime) ? "" : starttime);
        postParam.append("&endtime=").append(StringUtils.isEmpty(endtime) ? "" : endtime);
        postParam.append("&CustName=").append(StringUtils.isEmpty(CustName) ? "" : CustName);
        postParam.append("&SnType=").append(StringUtils.isEmpty(SnType) ? "" : SnType);
        postParam.append("&SnSubType=").append(StringUtils.isEmpty(SnSubType) ? "" : SnSubType);
        postParam.append("&SerialNo=").append(StringUtils.isEmpty(SerialNo) ? "" : SerialNo);
        postParam.append("&Status=").append(StringUtils.isEmpty(Status) ? "" : Status);

        return pokeRequestServe
                .transPost(url.toString(), "2.54查询服务报告数据", "GetAllServiceInfoHandle", postParam.toString());
    }

    @Override
    public JSONObject getInstrumentFile(String instrumentCode, String serviceNo, String enginnerId) {
        /** 调用CC端接口 2.51获取仪器配置清单接口 */
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("getInstrumentFile.asmx/getInstrumentFileHandle");
        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("InstrumentCode", instrumentCode);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.51获取仪器配置清单接口");
        interfaceOperationLog.setInterfaceType("getInstrumentFile");
        interfaceOperationLog.setServiceNo(serviceNo);
        interfaceOperationLog.setFseId(enginnerId);
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            log.info("调用CC端返回结果：" + interfaceResponseBody);
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        /** 如果调用接口异常直接返回 */
        if ("0".equals(interfaceState)) {
//            return new ResponseWithData().success().msg("查询失败 调用CC端获取FSE型号技能接口发生异常").code(202);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("code", 202);
            jsonObject.put("msg", "查询失败 调用CC端关闭接口发生异常");
            jsonObject.put("data", "");
            return jsonObject;
        }
        JSONObject obj = JSON.parseObject(interfaceResponseBody);
        JSONObject jsonStr = new JSONObject();
        jsonStr.put("msg", "查询失败");
        jsonStr.put("code", 203);
        jsonStr.put("data", obj);
        if (res != null) {
            if (res.code() == 200) {
                if ("1".equals(obj.getString("status"))) {
                    /** 获取CC端获取仪器数据接口信息 */
                    JSONArray data = obj.getJSONArray("record");
                    jsonStr.put("msg", "查询成功");
                    jsonStr.put("code", 200);
                    jsonStr.put("data", obj);
                    return jsonStr;
                }
            }
        }
        return jsonStr;
    }

    @Override
    public ResponseWithData<?> getEngineerByName(String fseName, String serviceNo, String enginnerId)
            throws Exception {
        /** 调用CC端接口 */
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("getEngineerByName.asmx/getEngineerByNameHandle");
//        url.append("&Teamleader_id=").append(TeamleaderId);

        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("FseName", fseName);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.50获取其他工程师接口");
        interfaceOperationLog.setInterfaceType("getEngineerByName");
        interfaceOperationLog.setServiceNo(serviceNo);
        interfaceOperationLog.setFseId(enginnerId);
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setInterfaceRequest("FseName=" + fseName);
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            log.info("调用CC端返回结果：" + interfaceResponseBody);
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        /** 如果调用接口异常直接返回 */
        if ("0".equals(interfaceState)) {
            return new ResponseWithData().success().msg("查询失败 调用CC端接口发生异常").code(202);
        }

        if (res.code() == 200) {
            JSONObject obj = JSON.parseObject(interfaceResponseBody);
            if ("1".equals(obj.getString("status"))) {

                /** 获取CC端TL名下工程师接口信息 */
                JSONArray jsonArr = obj.getJSONArray("record");

                /** 循环遍历返回的结果，数据库中存在的更新，不存在的插入 */
                if (jsonArr != null && jsonArr.size() > 0) {
                    for (int i = 0; i < jsonArr.size(); i++) {
                        // 获取每个人员信息对象
                        JSONObject jsonObject = jsonArr.getJSONObject(i);
                        // 员工ID
                        String enginner_id = jsonObject.getString("enginner_id") == null ? ""
                                : jsonObject.getString("enginner_id");
                        // 员工姓名
                        String NAME = jsonObject.getString("NAME") == null ? "" : jsonObject.getString("NAME");
                        // 工程师SAP Code
                        String sapcode =
                                jsonObject.getString("sapcode") == null ? "" : jsonObject.getString("sapcode");
                        // WorkDay休假状态  0 上班 1休假-上午 2休假-下午
                        String WorkDay =
                                jsonObject.getString("WorkDay") == null ? "" : jsonObject.getString("WorkDay");
                        User user = new User();
                        user.setEnginnerId(Long.parseLong(enginner_id));
                        List<User> list = userMapper.selectUserList(user);
                        user.setName(NAME);
                        user.setSapcode(sapcode);
                        user.setWorkday(WorkDay);
//                        user.setTeamleaderId(TeamleaderId);
//                        user.setTeamleaderName(tname);
                        if (list != null && list.size() > 0) {
                            user.setId(list.get(0).getId());
                            user.setUpdateTime(new Date());
                            userMapper.updateUser(user);
                        } else {
                            user.setCreateTime(new Date());
                            userMapper.insertUser(user);
                        }
                    }
                }

            }
        }
        return new ResponseWithData<>().success().msg("更新成功").code(200);
    }

    @Override
    public JSONObject CheckServiceEspecial(String serviceNo) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("CheckServiceEspecial.asmx/CheckServiceEspecialInfo");

        FormBody.Builder builder = new FormBody.Builder();
        builder.add("Service_no", serviceNo);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.67服务通知同普通费用及特殊费用接口");
        interfaceOperationLog.setInterfaceType("CheckServiceEspecial");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest("Service_no=" + serviceNo);
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        JSONObject obj = JSON.parseObject(interfaceResponseBody);

        return obj;
    }

    public JSONObject getCCErrorReportDetail(Map<String, String> map) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("syncErroReport.asmx/GetErroReportInfo");

        FormBody.Builder builder = new FormBody.Builder();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            builder.add(entry.getKey(), StringUtils.isEmpty(entry.getValue()) ? "" : entry.getValue());
        }

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.12同步Error report数据");
        interfaceOperationLog.setInterfaceType("detailErrorReport");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest("Service_no=" + map.get("service_no"));
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        JSONObject obj = JSONObject.parseObject(interfaceResponseBody);
        JSONArray jsonArray = obj.getJSONArray("record");

        JSONArray jsonArray1 = null;

        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = (JSONObject) jsonArray.get(i);
            jsonArray1 = jsonObject.getJSONArray("Pic_data");
            for (Object object1 : jsonArray1) {
                JSONObject json = (JSONObject) object1;
                String createTime = json.getString("CREATE_TIME");
                if (StringUtils.isNotEmpty(createTime)) {
                    DateTimeFormatter df = DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss.SSS");
                    String datee2 = df.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.valueOf(
                            createTime.substring(createTime.indexOf("(") + 1, createTime.indexOf("+")))),
                            ZoneId.of("Asia/Shanghai")));
                    json.put("CREATE_TIME", datee2.substring(0, 19));
                }
            }
            jsonObject.put("Pic_data", jsonArray1.toString());
        }
        return obj;
    }

    public JSONObject updatePartsUsedInfo(Map<String, String> map) {

        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("updatePartsUsed.asmx/updatePartsUsedInfo");
        StringBuffer postParam = new StringBuffer();
        postParam.append("part_id=")
                .append(StringUtils.isEmpty(map.get("part_id")) ? "" : map.get("part_id"));
        postParam.append("&state=")
                .append(StringUtils.isEmpty(map.get("state")) ? "" : map.get("state"));
        pokeRequestServe.transPost(url.toString(), "2.68.1备件是否使用到app状态修改", "updatePartsUsedInfo",
                postParam.toString());
        return null;
    }

    public void deleteCCParts(String partId) {
        Map<String, String> map = new HashMap();
        map.put("part_id", partId);
        map.put("state", "1");
        updatePartsUsedInfo(map);
    }

    public void addCCParts(String partId) {
        Map<String, String> map = new HashMap();
        map.put("part_id", partId);
        map.put("state", "0");
        updatePartsUsedInfo(map);

    }

    public JSONObject querypendingPartByFseIDHandle(String enginnerID) {
        return null;
    }

    public JSONObject getStHotAccountReportList(Map<String, String> map) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("syncHotAccountReport.asmx/GetHotAccountReportInfo");

        FormBody.Builder builder = new FormBody.Builder();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            builder.add(entry.getKey(), StringUtils.isEmpty(entry.getValue()) ? "" : entry.getValue());
        }

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.13同步Hot Account  report数据");
        interfaceOperationLog.setInterfaceType("getCCHotAccountReportList");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        interfaceOperationLog.setInterfaceRequest("Service_no=" + map.get("service_no"));
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        JSONObject obj = JSON.parseObject(interfaceResponseBody);

        return obj;
    }


    public JSONObject getOtherInstrumentHandle(String instrumentCode, String enginnerId) {

        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("getOtherInstrument.asmx/getOtherInstrumentHandle");
        StringBuffer param = new StringBuffer("InstrumentCode=").append(instrumentCode);
        param.append("&Engineer_id=").append("");
        ResponseWithData<?> data = pokeRequestServe
                .transPost(url.toString(), "获取其他设备信息接口", "getOtherInstrumentHandle", param.toString());
        JSONObject obj = JSON.parseObject(data.getData().toString());
        return obj;
    }

    public ResponseWithData<?> selectTransferWithName(String fseName) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("getEngineerByName.asmx/getEngineerByNameHandle");
//        url.append("&Teamleader_id=").append(TeamleaderId);

        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("FseName", fseName);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.6获取其它工程师接口");

        interfaceOperationLog.setInterfaceUrl(url.toString());
//        interfaceOperationLog.setInterfaceRequest(login.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            log.info("调用CC端返回结果：" + interfaceResponseBody);
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        /** 如果调用接口异常直接返回 */
        if ("0".equals(interfaceState)) {
            return new ResponseWithData().success().msg("查询失败 调用CC端获取TL名下工程师接口发生异常").code(202);
        }
        JSONArray jsonArr = null;
        if (res.code() == 200) {
            JSONObject obj = JSON.parseObject(interfaceResponseBody);
            if ("1".equals(obj.getString("status"))) {

                /** 获取CC端TL名下工程师接口信息 */
                jsonArr = obj.getJSONArray("record");
            }
            return new ResponseWithData<>().success(jsonArr).msg("查询成功").code(200);
        }
        return new ResponseWithData<>().error().msg("查询失败").code(201);
    }

    public ResponseWithData<?> selectTransferWithOutName(String fseId) {
        User user = new User();
        user.setDelFlag("0");
        user.setEnginnerId(new Long(fseId));
        List<User> userList = userMapper.selectUserList(user);
        if (ObjectUtils.isEmpty(userList)) {
            return new ResponseWithData<>().error().msg("查询不到该工程师").code(202);
        }
        String teamLeaderId = userList.get(0).getTeamleaderId();
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("getEngineerByTL.asmx/getEngineerByTLHandle");
//        url.append("&Teamleader_id=").append(TeamleaderId);

        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();

        User tempUser= userList.get(0);
        if("Team Leader".equals(tempUser.getPosition())){
            builder.add("Teamleader_id", fseId);
        }else{
            builder.add("Teamleader_id", tempUser.getTeamleaderId());
        }


        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.6获取TL名下工程师接口");

        interfaceOperationLog.setFseId(teamLeaderId);
        interfaceOperationLog.setInterfaceUrl(url.toString());
//        interfaceOperationLog.setInterfaceRequest(login.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            log.info("调用CC端返回结果：" + interfaceResponseBody);
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        /** 如果调用接口异常直接返回 */
        if ("0".equals(interfaceState)) {
            return new ResponseWithData().success().msg("查询失败 调用CC端获取TL名下工程师接口发生异常").code(202);
        }
        JSONArray jsonArr = null;
        if (res.code() == 200) {
            JSONObject obj = JSON.parseObject(interfaceResponseBody);
            if ("1".equals(obj.getString("status"))) {

                /** 获取CC端TL名下工程师接口信息 */
                jsonArr = obj.getJSONArray("record");
            }
            return new ResponseWithData<>().success(jsonArr).msg("查询成功").code(200);
        }
        return new ResponseWithData<>().error().msg("查询失败").code(201);
    }

    public ResponseWithData<?> getTeamSpares(String fseId, String partNo, String status) {
        List<User> userList = userMapper.getFseInformation(fseId);
        String teamLeaderId = userList.get(0).getTeamleaderId();
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("queryPartByTlId.asmx/queryPartByTlIdHandle");


        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("tl_id", teamLeaderId);
        builder.add("Engineer_id", "");
        builder.add("Part_no", partNo);
        builder.add("Status", status);
        builder.add("enginner_name", "");

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.52获取TL名下FSE备件接口");

        interfaceOperationLog.setInterfaceUrl(url.toString());
//        interfaceOperationLog.setInterfaceRequest(login.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            log.info("调用CC端返回结果：" + interfaceResponseBody);
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        /** 如果调用接口异常直接返回 */
        if ("0".equals(interfaceState)) {
            return new ResponseWithData().success().msg("查询失败 调用CC端获取TL名下备件接口发生异常").code(202);
        }
        JSONArray jsonArr = null;
        if (res.code() == 200) {
            JSONObject obj = JSON.parseObject(interfaceResponseBody);
            if ("1".equals(obj.getString("status"))) {

                /** 获取CC端TL名下工程师接口信息 */
                jsonArr = obj.getJSONArray("record");
            }
            return new ResponseWithData<>().success(jsonArr).msg("查询成功").code(200);
        }
        return new ResponseWithData<>().error().msg("查询失败").code(201);
    }

    @Override
    public String dispatchServicehandle(String sendId, Date sendDate, String serviceNo, String engineerId) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("DispatchService.asmx/DispatchServicehandle");
        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("send_id", sendId);
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        builder.add("send_time", sf.format(sendDate));
        builder.add("service_no", serviceNo);
        builder.add("engineer_id", engineerId);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.2.72APP指派/改派工程师");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);


        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            log.info("调用CC端返回结果：" + interfaceResponseBody);
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);

        return interfaceState;


    }

    @Override
    public String refuseServicehandle(String engineerId, String serviceNo) {
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("refuseService.asmx/refuseServicehandle");
        /** POST请求 参数赋值 */
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("engineer_id", engineerId);
        builder.add("service_no", serviceNo);

        /** 先保存接口参数 */
        InterfaceOperationLog interfaceOperationLog = new InterfaceOperationLog();
        interfaceOperationLog.setInterfaceName("2.2.73工程师拒绝服务");
        interfaceOperationLog.setInterfaceUrl(url.toString());
        interfaceOperationLog.setStartTime(new Date());
        iInterfaceOperationLogService.insertInterfaceOperationLog(interfaceOperationLog);

        Response res = null;
        String interfaceResponse = "";
        String interfaceResponseBody = "";
        String interfaceState = "";
        try {
            /** 调用CC端接口 */
            res = OkHttpUtils.getInstance().postRequest(url.toString(), builder.build());
            interfaceResponse = res.toString();
            interfaceResponseBody = res.body().string();
            interfaceResponse += " Body参数：" + interfaceResponseBody;
            log.info("调用CC端返回结果：" + interfaceResponseBody);
            if (res.code() == 200) {
                interfaceState = "1";
            } else {
                interfaceState = "2";
            }
        } catch (Exception e) {
            log.error("调用CC接口异常：" + e.getMessage() + "," + interfaceResponseBody);
            interfaceResponse = e.getMessage();
            interfaceState = "0";
        }

        /** 更新接口返回结果 */
        interfaceOperationLog.setEndTime(new Date());
        interfaceOperationLog.setInterfaceResponse(interfaceResponse);
        interfaceOperationLog.setInterfaceState(interfaceState);
        iInterfaceOperationLogService.updateInterfaceOperationLog(interfaceOperationLog);
        return interfaceState;

    }

	@Override
	public ResponseWithData<?> getServiceSignPicHandle(String serviceNo) {
	   // cc地址
        String ccServerUrl = global.getCcServerUrl();
        StringBuffer url = new StringBuffer();
        url.append(ccServerUrl);
        url.append("getServiceSignPic.asmx/getServiceSignPicHandle?service_no=");
        url.append(serviceNo);
        String ccName="获取服务通知签名图片";
        String ccType="getServiceSignPicHandle";
        StringBuffer postParam = new StringBuffer();
        postParam.append("").append(serviceNo);
        return pokeRequestServe.transGet(url.toString(), ccName, ccType);
	}
}